39

I have a Java EE Web Application which connects to a SQL Server 2008 instance. I don't have any problem connecting and retrieving to all my tables, except for one of them. The error in the Tomcat log is:

WARNING: Failed to load the sqljdbc_auth.dll cause :- no sqljdbc_auth in java.library.path

user247702
  • 23,641
  • 15
  • 110
  • 157
AFF
  • 1,515
  • 4
  • 21
  • 35
  • You can try the answer on the following link http://stackoverflow.com/questions/23949890/java-lang-unsatisfiedlinkerror-no-sqljdbc-auth-in-java-library-path – VinceMok Aug 15 '16 at 16:44

8 Answers8

56

1) Download the JDBC Driver here.


2) unzip the file and go to sqljdbc_version\fra\auth\x86 or \x64
3) copy the sqljdbc_auth.dll to C:\Program Files\Java\jre_Version\bin
4) Finally restart eclipse

Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118
Amine Soumiaa
  • 683
  • 5
  • 13
19

Here are the steps if you want to do this from Eclipse :

1) Create a folder 'sqlauth' in your C: drive, and copy the dll file sqljdbc_auth.dll to the folder

1) Go to Run> Run Configurations

2) Choose the 'Arguments' tab for your class

3) Add the below code in VM arguments:

-Djava.library.path="C:\\sqlauth"

4) Hit 'Apply' and click 'Run'

Feel free to try other methods .

nanospeck
  • 3,388
  • 3
  • 36
  • 45
  • great option here leveraging the `java.library.path` argument. saved me a ton of headache as the users can't copy/paste to the `C:\Program Files` folder. thanks! – Matt Felzani May 29 '20 at 03:27
  • Oh my goodness thank you so much. I was driving myself mad going through dozens of different approaches that don't work. – Adam Gripton Dec 07 '21 at 15:17
  • The methods link that you added was a useful read that helped explain a little of the why. Thank you for this solution which I finally came to after two days on this issue. Very frustrating that Classpath doesnt seem to do its job, but perhaps it is my newness to Java. . .I am not a fan thus far due to these fragilities – MDGREEE Mar 21 '23 at 15:21
11

For easy fix follow these steps:

  1. goto: https://learn.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url#Connectingintegrated
  2. Download the JDBC file and extract to your preferred location
  3. open the auth folder matching your OS x64 or x86
  4. copy sqljdbc_auth.dll file
  5. paste in: C:\Program Files\Java\jdk_version\bin
  6. restart either eclipse or netbeans
jfindley
  • 682
  • 7
  • 6
6

The error is clear, isn't it?

You've not added the path where sqljdbc_auth.dll is present. Find out in the system where the DLL is and add that to your classpath.

And if that also doesn't work, add the folder where the DLL is present (I'm assuming \Microsoft SQL Server JDBC Driver 3.0\sqljdbc_3.0\enu\auth\x86) to your PATH variable.

Again if you're going via ant or cmd you have to explicitly mention the path using -Djava.library.path=[path to MS_SQL_AUTH_DLL]

afrin216
  • 2,295
  • 1
  • 14
  • 17
  • 3
    The problem is here: I have searched internet, the response was like your response but I DON'T HAVE THIS DLL FILE IN MY COMPUTER!!!! – AFF Jul 29 '12 at 06:41
  • 3
    Well then we have a problem, rite? I think you haven't installed the driver at all! Go to this link - http://msdn.microsoft.com/en-us/library/ms378428%28v=sql.90%29.aspx . They give step by step on how to install and use – afrin216 Jul 29 '12 at 06:47
  • 6
    @andrewrjones The JDBC driver does. However, it cannot connect using a Trusted Connection without this DLL. You can do a username/password connection - just not a trusted connection. – RB. Sep 26 '13 at 13:02
  • For me adding to CLASSPATH was not enough, had to add to Path too – Dima Fomin Feb 15 '19 at 16:08
  • 1
    It's not clear at all. I add maven dependency, it should be there, why do I have to manually download and install it? – wilmol Apr 21 '21 at 02:59
3

I've just encountered the same problem but within my own application. I didn't like the solution with copying the dll since it's not very convenient so I did some research and came up with the following programmatic solution.

Basically, before doing any connections to SQL server, you have to add the sqljdbc_auth.dll to path.. which is easy to say:

PathHelper.appendToPath("C:\\sqljdbc_6.2\\enu\\auth\\x64");

once you know how to do it:

import java.lang.reflect.Field;

public class PathHelper {
    public static void appendToPath(String dir){

        String path = System.getProperty("java.library.path");
        path = dir + ";" + path;
        System.setProperty("java.library.path", path);

        try {

            final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
            sysPathsField.setAccessible(true);
            sysPathsField.set(null, null);

        }
        catch (Exception ex){
            throw new RuntimeException(ex);
        }

    }

}

Now integration authentication works like a charm :).

Credits to https://stackoverflow.com/a/21730111/1734640 for letting me figure this out.

Pawel Gorczynski
  • 1,227
  • 1
  • 15
  • 17
3

I had to use windows authentication and I tried every suggested solution out there but with no success till I changed the name of the auth file as follows:

old-name: mssql-jdbc_auth-10.2.0.x64.dll

new-name: sqljdbc_auth.dll

And then it worked!

I looked up for this case to understand it more, apparently for Windows operating systems, the driver looks for sqljdbc_auth.dll by default.

Here is a useful link I've found:

https://learn.microsoft.com/en-us/sql/connect/jdbc/feature-dependencies-of-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver15

Amira
  • 180
  • 2
  • 9
2

To resolve I did the following:

  1. Copied sqljdbc_auth.dll into dir: C:\Windows\System32
  2. Restarted my application
TedEd
  • 621
  • 6
  • 9
0

I resolved the issue by:

  1. Upgrading com.microsoft.sqlserver from 6.1.0.jre8 to 10.1.0.jre8-preview:

    <dependency>
         <groupId>com.microsoft.sqlserver</groupId>
         <artifactId>mssql-jdbc</artifactId>
         <version>10.1.0.jre8-preview</version>
    </dependency>
    
  2. Adding missing dependency:

     <dependency>
         <groupId>net.sourceforge.jtds</groupId>
         <artifactId>jtds</artifactId>
         <version>1.3.1</version>
     </dependency>
    
  3. Using the following jdbc connection:

jdbc:sqlserver://;authenticationScheme=NTLM;integratedSecurity=true;domain=;databasename=;encrypt=true;trustServerCertificate=true;user=;password=

Eyal Sooliman
  • 1,876
  • 23
  • 29