I have one more question. I am connectinag to SQL Server 2008, not express, and I keep getting the "login failed for user "...""

The connection string I am using is:

Dim connStrg As String = "Data Source=" _
           & ServerAdressTextBox.Text & _
           ";Initial Catalog=" & _
           DatabaseNameTextBox.Text & _
           "Integrated Security=SSPI" & ";"

Does anyone know where I am going wrong? If anyone knew anything that could help point me in the right direction, it would be GREATLY appreciated.

Thank you all for your time.

6 Years
Discussion Span
Last Post by Begginnerdev

I usually use ADO and I use the connection string

"Driver={SQL Server};Server=" % server & ";Database=" & database & ";Trusted_Connection=yes;"

Edited by Reverend Jim: n/a


I have posted the wrong string. I am sorry, that is the CE string. This is the string I am using.

Dim connStrg As String = "Data Source=" & ServerAdressTextBox.Text & _
                         "\MSSQL;Initial Catalog=" & DatabaseNameTextBox.Text _
                         & ";User Id=" & UserNameTextBox.Text & ";Password=" & _
                         PasswordTextBox.Text & ";"

I am sorry.


If you are using integrated security then you are logged in to SQL Server based on your Windows logon ID. That ID has to be defined to SQL Server as having access rights to the databases that you want to connect to.

Your first example uses Integrated Security on SQL Server. Your second example uses a non-Windows userid and password and NOT on SQL Server. So please decide what it is you want to connect to and how, and we'll try to help.


When using the Windows Authentication connection string, I get the error, "Login failed for user '" , but when I use the other string it returns "Login failed for user "username"".


I need windows authentication, but I think there is something wrong in my syntax.

Dim connStrg As String = "Data Source=" & ServerAdressTextBox.Text & _
                                     ";Initial Catalog=" & _
                                     DatabaseNameTextBox.Text & _
                                     "Trusted Connection=True;"

Let's replace the variables with tokens. For example, let's replace ServerAdressTextBox.Text with the string SERVER, etc, and see how your connection strings look at that point. Your three examples boil down to

"Data Source=SERVER;Initial Catalog=DATABASEIntegrated Security=SSPI" & ";"

"Data Source=SERVER\MSSQL;Initial Catalog=DATABASE;User Id=USERNAME;Password=PASSWORD;"

"Data Source=SERVER;Initial Catalog=DATABASETrusted Connection=True;"

When you look at the resulting strings you can see that you are missing the delimiter ";" following the DATABASE name in examples 1 and 3. Correct that first and see where it gets you.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.