Skip to content Skip to sidebar Skip to footer

SQL Server Log In Failing From Java DriverManager.getConnection(), Working From Python With Pymssql.connect()

I'm trying to use DriverManager.getConnection() to connect to a SQL Server db from a Java application, but I keep getting 'Login failed for user' errors with it. I've tried using b

Solution 1:

pymssql is built on top of FreeTDS. Both FreeTDS and jTDS support an older Windows authentication scheme named NTLM, while current versions of Microsoft's JDBC Driver for SQL Server (mssql-jdbc) no longer support that authentication mechanism.

So, given that you've confirmed that pymssql can connect, you should be able to connect from your Java app as Windows user MYDOMAIN\username using jTDS like so:

String myUid = "username", myPwd = "mypassword";
String connUrl = "jdbc:jtds:sqlserver://192.168.1.123:1433/databasename;DOMAIN=MYDOMAIN";
Connection conn = DriverManager.getConnection(connUrl, myUid, myPwd);

Solution 2:

To find out the reason of "Login failed for user" one should go to SQL Server error log.

The next row to 18456 error will give you the reason.

The most probably reason of failure in your case is that the server is configurated to use Windows Authentication only


Post a Comment for "SQL Server Log In Failing From Java DriverManager.getConnection(), Working From Python With Pymssql.connect()"