1

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 :)

LaPalme
  • 339
  • 5
  • 16

1 Answers1

4

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.

Ihor Dobrovolskyi
  • 1,241
  • 9
  • 19
  • I just come back to add a detail. It actually works in the Eclipse I have installed on my Windows machine, but when using the Eclipse I was talking about, on a Linux machine on the company's network, it still doesn't work even with the good version of the sqljdbc_auth.dll. So finally the problem is solved because I have an Eclipse on my Windows machine. – LaPalme Jul 10 '17 at 12:01
  • @LaPalme If you have one more problem on a Linux machine, you can ask another question and someone will help you. – Ihor Dobrovolskyi Jul 10 '17 at 12:06
  • Actually it's the same problem that I could solve with your answer on another Eclipse directly installed on my Windows machine. So for me it's ok now, but I just wanted to say for those reading this post that for the Eclipse on the Linux machine, as mentioned in my question, it still doesn't work. That's all :) Thank you and have a nice day – LaPalme Jul 10 '17 at 12:16