32

i must connect to a sql server with windows authentication

sql server is on machine 192.168.3.6 web server (client) is on my machine 192.168.3.10

I'm using JTDS driver

dbUrl=jdbc:jtds:sqlserver://192.168.3.6:1099/db_test;instance=test
Connection con = DriverManager.getConnection( dbUrl, "", "" );

I have username and password of administrator user of sql server !

I also put ntlmauth.dll into c:\windows and c:\windows\system32 and I have always error:

java.sql.SQLException: Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection.

Any idea to solve my problem ? Thank you very much

Gerhard Schlager
  • 3,155
  • 1
  • 31
  • 53
Federico Artebani
  • 323
  • 1
  • 3
  • 4

2 Answers2

50

See jTDS FAQ http://jtds.sourceforge.net/faq.html

you will have to pass useNTLMv2=true and domain=yourdomain

ajay_whiz
  • 17,573
  • 4
  • 36
  • 44
  • 4
    Wonderfull, I have resolved dbUrl=jdbc:jtds:sqlserver://192.168.3.6:1099/db_test;instance=test;useNTLMv2=true;domain=workgroup Connection con = DriverManager.getConnection( dbUrl, dbUser, dbPwd ) I must use parameters useNTLMv2=true and domain. The value of parameter domain is no important. It works also with domain=pippo !! I do not know how .....:-) – Federico Artebani Sep 10 '10 at 10:50
  • Any ideas as to why this would work with TC but not with DBVisualizer with exact same parms ? – killjoy Jun 05 '19 at 21:22
  • I did not see addressed the issue of entering a password for a connection string; seems to have been sidestepped. Can someone suggest something? – MSIS Jan 15 '21 at 03:32
2

What you can do is something like:

String url = "jdbc:jtds:sqlserver://MYPC/MYDB;instance=SQLEXPRESS";
Class.forName("net.sourceforge.jtds.jdbc.Driver");
Connection conn = DriverManager.getConnection(url);

Make sure you have jtds.jar in the Java build path.

Also, add "-Djava.library.path="PATH\JTDS\x64\SSO" where 'Path' is where your SSO folder is after installing the JTDS driver (this is where you have your ntlmauth.dll).

Here is a short step-by-step guide showing how to connect to SQL Server using jTDS (as well as JDBC) with Windows authentication should you need more details. Hope it helps!

Thusi
  • 929
  • 7
  • 5