简体   繁体   中英

no sqljdbc_auth in java.library.path

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

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

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 .

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]

For easy fix follow these steps:

  1. goto: https://docs.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

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.

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

To resolve I did the following:

  1. Copied sqljdbc_auth.dll into dir: C:\\Windows\\System32
  2. Restarted my application

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=

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM