Reputation:
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
Upvotes: 1
Views: 5812
Reputation: 15011
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;
Upvotes: 7
Reputation: 65435
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.
Upvotes: 15