LaPalme
LaPalme

Reputation: 339

I don't understand why "no sqljdbc_auth in java.library.path" persists

I am trying to connect a java program to an SQL Server database.

The important is that I am working on a Windows 7 machine, my Eclipse is on a Linux machine on my company's network, and the SQL Server requests a Windows authentication.

I copied and pasted the driver sqljdbc41.jar in the location of my project (on Eclipse right click on the project, properties and see location). I also pasted the sqljdbc_auth.dll in the same location. I have tried to add the path to this .dll on the "Native Library location following this post : https://stackoverflow.com/a/958074/7812989 . But I still have this error :

    Jul 10, 2017 10:52:35 AM com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit>
WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId:39389d4c-36cd-459f-b9f8-15d3cf422b34
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2397)
    at com.microsoft.sqlserver.jdbc.AuthenticationJNI.<init>(AuthenticationJNI.java:68)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3132)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:43)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3123)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7505)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2445)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1981)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1628)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1459)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:773)
    at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1168)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at sqlconnectiontest.SqlSelection.main(SqlSelection.java:19)
Caused by: java.lang.UnsatisfiedLinkError: no sqljdbc_auth in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1878)
    at java.lang.Runtime.loadLibrary0(Runtime.java:849)
    at java.lang.System.loadLibrary(System.java:1087)
    at com.microsoft.sqlserver.jdbc.AuthenticationJNI.<clinit>(AuthenticationJNI.java:41)
    ... 13 more

My code is the following :

    package sqlconnectiontest;

    import java.sql.*;

    public class SqlSelection {

        /**
         * @param args
         */
        public static void main(String[] args) {
            try
            {
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

                String userName = "myUser";
                String password = "myPassword";
                String url = "jdbc:sqlserver://fr0-iaascls-190.eu.company.corp:10001;databaseName=MYDATABASE;integratedSecurity=true;";
                Connection con = DriverManager.getConnection(url, userName, password);    
            } 
            catch (Exception e)
            {
                e.printStackTrace();
            }

        }
    }

Do you have an idea that may help please ? Thank you :)

Upvotes: 1

Views: 9228

Answers (1)

Ihor Dobrovolskyi
Ihor Dobrovolskyi

Reputation: 1241

You may get this error message if the application is trying to use the incorrect architecture (x86 VS x64) version of the sqljdbc_auth.dll. Try specifying the directory path to the other architecture.

If you are on a x64 machine running x64 OS, but the JVM you are using is the x86 version, you will need to specify and use the x86 version of the sqljdbc_auth.dll.

Upvotes: 4

Related Questions