Stiaanvm Stiaanvm - 1 year ago 88
SQL Question

ODBC login is trying to use Windows authentication even though I supply SQL Server credentials

I am having trouble connecting to my Microsoft Server 2008 using the JdbcOdbc driver in Java. I prefer to use the Jdbc driver over the windows driver as the client has multiple options to connect with. The connection string I am using is:

jdbc:odbc:Driver={SQL Server};SERVER=hostname;database=CadSysDB;user=sqlusername;pass=sqlpassword;}

The server does not make use of Windows Authentication, but SQL Authentication.

The error I am receiving is:

java.sql.SQLException: [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed. The login is from an untrusted domain and cannot be used with Windows authentication.

I believe it could be a problem in my connection string, any advice?

Answer Source

The Driver={SQL Server} ODBC driver does not recognize user= as a connection string parameter name so it tries to log into the SQL Server without passing any SQL Server credentials (i.e., using Windows Authentication).

Passing the SQL Server credentials using the Uid= and Pwd= parameters


will get the {SQL Server} ODBC to try and log in using SQL Authentication. We can also explicitly pass a parameter for Trusted_Connection=no, but that is not really required if Uid and Pwd are provided.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download