1

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
  • 2
    I like this site a lot for helping out with these types of questions: connectionstrings.com Commented Oct 15, 2008 at 22:51

2 Answers 2

15

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.

Sign up to request clarification or add additional context in comments.

Comments

7

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.