Hi all; i'm trying to connect my program to an SQL Server Express database... however i am just getting an error that simply states:

"Login failed for user 'sa'."

Within my code this appears on:
objConnection.Open()

my code so far is:

Imports System.Data.SqlClient
Imports System.Data

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim objConnection As SQLConnection = New _
SqlConnection("Server=[ServerName];Database=[DatabaseName];" & _
"user id=sa;password=")

Dim objCommand As SqlCommand = New SqlCommand()

objCommand.Connection = objConnection

objConnection.Open()

ComboBox1.Text = objCommand.CommandText = "SELECT DISTINCT UserName" & _
"FROM tblUsers;"

objConnection.Close()

End Sub

Essentially i am trying to connect to the Sql server database and draw the contents of the UserName column into the combobox.
Any advice on where i'm going wrong? Thanks

ok stupid question: did u set a password for user sa? i think it have a password by default.

ok stupid question: did u set a password for user sa? i think it have a password by default.

Also the 'sa' account can be enabled/disabled. Make sure you have the proper password and the account has been enabled.

r u using windows authentication login

Atove,

SQL Express database allows Integrated Windows authentication scheme only. So, your connection string for MS-SQL remote database might be,

Dim Cn As SQLConnection
Cn = New SqlConnection("Data Source=.\SQLEXPRESS;Initial Catalog=tempdb;Integrated Security=True")

NOTE: Integrated Security=True - This property automatically uses windows os credentials.

@GeekByChoice - ok stupid question.
-- DON'T offend peoples.

@GeekByChoice - ok stupid question.
-- DON'T offend peoples.

i didnt :|
i didnt say he ask'd a stupid question. i felt like i ask a stupid question o.O

Thanks for the assistance guys; it was a combination of things that were preventing this from working.

I had a look at the 'sa' account and found it wasn't enabled; i then had password difficulty but managed to set it in the end.

I then had another look at my code and made some alterations; below is the working code:

Dim objConnection As SqlConnection = New  _
        SqlConnection("Server=[ServerName];Database=[DatabaseName];user id=sa;password=password")

        Dim objCommand As SqlCommand = New SqlCommand()

        objCommand.Connection = objConnection

        objCommand.CommandText = "SELECT DISTINCT UserName " & _
                           "FROM tblUsers;"

        Dim com As New SqlCommand(objCommand.CommandText, objConnection)

        Dim da As SqlDataReader
        objConnection.Open()
        da = com.ExecuteReader
        While da.Read
            cboUserName.Items.Add(da("UserName"))
        End While
        objConnection.Close()

Once again; thanks for all your help! I really appreciate it. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.