38

I am trying to run the following bit of code:

import java.sql.DriverManager;

public class Connect {
    public static void main(String[] args){
        try{
            String databaseDriver = "net.sourceforge.jtds.jdbc.Driver";
            Class.forName(databaseDriver);
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        try{
            String url = "jdbc:jtds:sqlserver://BHX:1433/Forecast;instance=SQLEPXRESS";
            java.sql.Connection con = DriverManager.getConnection(url);
            System.out.println("Connection");
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }
}

My SQL server is running on port 1433 on machine BHX.

The error message I'm getting is as follows:

java.sql.SQLException: I/O Error: SSO Failed: Native SSPI library not loaded. Check the     java.library.path system property.
    at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:615)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:352)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:185)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at Connect.main(Connect.java:14)
Caused by: java.io.IOException: SSO Failed: Native SSPI library not loaded. Check the java.library.path system property.
    at net.sourceforge.jtds.jdbc.TdsCore.sendMSLoginPkt(TdsCore.java:1893)
    at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:588)
    ... 6 more

I've read up on why this usually occurs and found a similar question here, but this doesn't seem to work. When running the code I've inlcuded the following argument to locate the SSO file:

-Djava.library.path=/Tester/jdbc/x64/SSO

And this is the structure of my files

**Tester**
   *src*
     default package
         Connect.java
   *JRE System Library*
   *jdbc*
     conf
     html
     IA64
     x64
       SSO
        ntlmauth.dll
     x86

Can you spot anything wrong?

Amnon
  • 2,212
  • 1
  • 19
  • 35
Nosheen
  • 458
  • 1
  • 5
  • 12

6 Answers6

76

Seems like the same issue as this one: jtds-driver-not-working-for-sql-sever-2008r2-and-denali-native-sspi-library-not

You should drop the appropriate ntlmauth.dll file from the JTDS download package into your JRE bin folder.

If you're running on a 64bit Windows machine:

  • This 32bit DLL:

    Downloads >>> jtds-1.3.0-dist.zip >>> x86 >>> SSO >>> ntlmauth.dll

  • Goes here in this 32bit JRE location:

    C:\Program Files (x86)\Java\jre7\bin

  • This 64bit DLL:

    Downloads >>> jtds-1.3.0-dist.zip >>> x64 >>> SSO >>> ntlmauth.dll

  • Goes here in this 64bit JRE location:

    C:\Program Files\Java\jre7\bin

If you're running on a 32bit Windows machine:

  • This 32bit DLL:

    Downloads >>> jtds-1.3.0-dist.zip >>> x86 >>> SSO >>> ntlmauth.dll

  • Goes here in this 32bit JRE location:

    C:\Program Files\Java\jre7\bin

If that doesn't work then try adding this line at the top of your main method: System.out.println(java.lang.System.getProperty('java.library.path'));

It should output the actual JRE path being used by your program. Make sure the appropriate ntlmauth.dll is in that JRE's bin folder.

NOTE: Do NOT set the domain, user, or password properties of the connection when utilizing this method.

NOTE: If your Java client program is running on a non-windows machine, you're out of luck using the ntlmauth.dll method. This is a quote from the documentation included with the JTDS download package: Downloads >>> jtds-1.3.0-dist.zip >>> README.SSO

Starting with release 0.9.2 jTDS is capable of using the Windows credentials of the current user under whose account the client program is running to login to SQL Server (Windows Single Sign On).

Using Windows Single Sign On (SSO) clients will be able to connect to Microsoft SQL Server without providing credentials. It would dynamically read current user's credentials and connect to the database. provided that the Windows account has enough rights in the database. This is done using a native (Windows-only) library, ntlmauth.dll.

Community
  • 1
  • 1
Rob.Kachmar
  • 2,129
  • 1
  • 18
  • 23
  • 1
    Very useful, but instead of adding ntlmauth.dll to the jre directory I had to add it to the sdk directory: C:\Program Files\Java\jdk1.7.0_17\bin – Steffen Feb 13 '14 at 17:02
  • @Rob.Kachmar Why do you suggest not setting the domain? I just ran it with it set and without it set, and both worked fine. – Jeremy W May 20 '15 at 19:58
  • Using 0xDBE? Copy `x86\SSO\ntlmauth.dll` from the jTDS dist zip file into `C:\Program Files (x86)\JetBrains\0xDBE 139.795.5\jre\jre\bin`. – bonh Jun 05 '15 at 19:29
  • I needed to copy the .dll file to `C:\Program Files\Java\jdk1.8.0_77\jre\bin` – Tiago Sippert Apr 12 '16 at 17:19
  • I've placed this dll in all the folders mentioned above with no luck. I'm running an RCP application with Java 1.7 and Eclipse Helios. It works fine if I include username and password, but get this error when I use integratedSecurity=true – dead_jake Sep 29 '16 at 14:46
  • Thank you! This is exactly what I needed. I'm working with SymmetricDS to sync my db's but I couldn't use integrated security with the jtds driver. Dropped the ntlm dll's in like suggested and using `jdbc\:jtds\:sqlserver\://localhost\:1433/mydb;useKerberos=true;sendStringParametersAsUnicode\=false;useCursors\=true;bufferMaxMemory\=10240;lobBuffer\=5242880;socketTimeout\=15;appName\=symds` for `db.url` – Kevin Aung Dec 21 '17 at 02:40
  • It's worth mentioning that some app servers will need to be restarted, since few pick these dlls dynamically – access_granted Mar 07 '18 at 01:05
  • With my CommandBox-based Lucee, I had to copy the DLL file into my ``C:\Windows\System32`` path, as the error message persisted even after copying it to various ``bin`` directories here. – Gogowitsch Mar 18 '18 at 19:42
8

I had a similar problem and I tried to place the ntlmauth.dll file in as many directories I thought sql-developer would go looking for it. I finally got it to work by placing the ntlmauth.dll file in the \jdk\jre\bin folder in the sql-developer application directory itself (i.e. sql-developer\jdk\jre\bin). Why would sql-developer look for the ntlmauth.dll in in this folder and not the system folder is beyond my level of understanding. In any case, it worked.

Below is a link to a similar question that I just answered.

Oracle SQL Developer connection to Microsoft SQL Server

codingknob
  • 11,108
  • 25
  • 89
  • 126
  • 1
    Note that once you've placed the file in this folder, you need to restart Oracle SQL Developer. – Mir May 26 '15 at 20:26
5

I am getting the same error even after successfully placing ntmauth.dll file in JRE/bin.

Then I tried by putting ntmauth.dll in the C:\Windows\System32 directory. By doing so the issue got fixed.

Gogowitsch
  • 1,181
  • 1
  • 11
  • 32
TechSunil
  • 141
  • 2
  • 1
  • This answer is what ultimately worked for me, thank you. Also, I had to start SQL Developer using the `runas` command: `runas /netonly /user:DOMAIN\User "path-to-sql-developer.exe"`. – Jason Robinson Apr 13 '18 at 02:54
1

Good job.

But, there's a little problem when deploying your JAR file!

I suggest to create a folder (for example, lib) and copy all native libraries in. Finally add a Java execution parameter:

java -jar your_jar.jar -Djava.library.path=./lib

This was inspired from JTDS driver not working for SQL Server 2008R2 and Denali Native SSPI library not loaded.

Community
  • 1
  • 1
Said AKHROUF
  • 225
  • 3
  • 10
  • Personally, I took this a step further and included the path to the lib folder on the class path. This helps ensure that any native libraries go with the application when compiled into an executable form. – nihilon Oct 18 '15 at 04:10
1

Failing to pass authentication parameters results in the same error, so alternatively to the other answers you can also pass the username and password in the connection string, e.g.

jdbc:jtds:sqlserver://localhost:1433/dbname;user=username;password=s3cr3t
isapir
  • 21,295
  • 13
  • 115
  • 116
0

I got it working by placing the ntlmauth.dll file at \jdk\jre\bin. I am using Tomcat as my application server.

However, I noticed that this works for only one web application deployed at a time. If I have the same setting for multiple web applications, all fail but one. This is quite a strange behavior. Any idea what's happening here?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
shirjai
  • 243
  • 2
  • 5
  • 20
  • This does not really provide an answer to the question. To ask a new question, use the "Ask Question" button at the top of the page. You can link to this question if it helps provide context. – elixenide Nov 18 '15 at 14:11