Scott
Scott

Reputation:

Why won't my c# connection string to a SQL server work with Windows authentication?

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

Answers (2)

JamesSugrue
JamesSugrue

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

yfeldblum
yfeldblum

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

Related Questions