tags:

views:

2902

answers:

5

Why won't my connection string to SQL server work with Windows authentication? A sql user works fine, acme\administrator or [email protected] won't work. This is a Win Form app written in C#.

    {
        OdbcConnection cn = null;
        String connectionString;
            connectionString = "Driver={SQL Server};Server=" + cbxDataSources.Text +";Database=" + strDatabase + ";";

            connectionString += "UID=" + textBoxUserName.Text + ";";
            connectionString += "PWD=" + textBoxPassword.Text + ";";

        cn = new OdbcConnection(connectionString);
        return cn;
    }

Thanks guys

+1  A: 

Is there any error messages?

Craig
+13  A: 

You are using SQL Server authentication.

Windows authentication authenticates your connection with the Windows identity of the currently executing process or thread. You cannot set a username and password with Windows authentication. Instead, you set Integrated Security = SSPI.

Justice
+6  A: 

You have to connect using a Trusted Connection.

2005:

Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Trusted_Connection=yes;

2000:

Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Trusted_Connection=Yes;
KiwiBastard
A: 

Trusted_Connection=Yes; was what I needed, thanks for that. Can Trusted_Connection=Yes; be used for both sql authentication and windows authentication? It seems to work with both?

Thanks

No. Trusted_Connection / Integrated Security *means* Windows authentication, and UID/PWD *means* SQL authentication.
Justice
A: 

check the following link

http://csharp.net-informations.com/ado.net/csharp-connection-string.htm

bolton.

bolton