kazinix
kazinix

Reputation: 30093

SQL Server 2000 / ODBC - Not associated with a trusted SQL Server connection

I get this error:

ERROR [28000] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.

Here's my code (C#), I'm running this on a local and on a remote machine:

    using (OdbcConnection connection = new OdbcConnection("dsn=mydsn"))
    {
        connection.ConnectionTimeout = 50000;

        OdbcCommand command = new OdbcCommand("select * from users", connection);
        command.CommandTimeout = 50000;

        connection.Open();
        OdbcDataReader reader = command.ExecuteReader();
    }

DSN details:

name: mydsn
SQL login: mylogin
database: Test

SQL Server Configuration:

security: sql server and windows authentication mode

Whenever I try to use use the login to Management Studio, everything works fine, I can execute queries.

Upvotes: 1

Views: 4727

Answers (2)

kazinix
kazinix

Reputation: 30093

ODBC ALWAYS uses a trusted connection so the user account (on Windows) must have required privileges to access the database.

Upvotes: 1

LadyRoot
LadyRoot

Reputation: 81

Check the SQL client network utility and list the possible client protocols. At least two should be enabled (by default):

  1. TCP/IP
  2. Named Pipes

I got rid of this error as soon as I've put TCP/IP first, named pipes second after switching to Windows Authentication only.

However, you may notice, that "trusted SQL Server Connection" usually refers to Windows Authentication only. If I were you, I would check the connection via osql first with your login and pass.

Upvotes: 1

Related Questions