Question

This is weird, I am connecting to a sql server 2008 instance that has integrated authentication configured for windows. I found a way to bypass integrated authentication it by doing this in code:

Connection con = DriverManager.getConnection( "jdbc:jtds:sqlserver://mydbserver/myDbname;useNTLMv2=true;username=$jboss;password=1234;domain=MYDOMAIN", "$jboss", "1234");

So that above after doing the class for name on the jtds drivers it works perfect. However, I need to put this as a connection string in a config file and when I change the above to use the method call on getConnection without explicity sending in the username,password params like this:

 Connection con = DriverManager.getConnection( "jdbc:jtds:sqlserver://mydbserver/myDbname;useNTLMv2=true;username=$jboss;password=1234;domain=MYDOMAIN");

I get a Native SSPI library not loaded exception because its trying to authenticate using windows authentication. So I find the dll in the jts distribution add ntlmauth.dll to my bin and system classpath and then I get an untrusted domain login exception which I know I can resolve by doing "RUNAS.exe " under the domain but that gets me back to having to use integrated authentication which I don't want.

The question comes down to, why can I create a Connection without any issues by passing in the username and password as params on the getConnection() method but when I don't it forces integrated authentication. This would not be an issue if I created the Connection myself in code but I need a single connection string to put in my properties file and don't know how to construct a connection string that will call getConnection() and supply the username,password as params.

I hate these tedious issues have Googled but have come up empty handed, any input would help. - Duncan

Was it helpful?

Solution

The parameter is user, not username. That should fix your issues. So try:

 Connection con = DriverManager.getConnection( "jdbc:jtds:sqlserver://mydbserver/myDbname;useNTLMv2=true;user=$jboss;password=1234;domain=MYDOMAIN");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top