SQLException: this driver is not configured for integrated authentication tomcat
Asked Answered
M

3

8

Am trying to connect MS SQL server through java web applications.

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

connection= DriverManager.getConnection("jdbc:sqlserver://localhost;databaseName=XXX;integratedSecurity=true");

I have copied "sqljdbc_auth.dll" to $Tomcat_home/bin and copied jar into $Tomcat_home/lib folder.

I Have multiple web apps in same tomcat instance.

The first webApp loads and successfully establishes the connection with MS SQL.

But the remaining apps fail to connect to MS SQL prompting:

com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId:41d72756-1383-427e-8c4f-c3075ae1559a
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2400)
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)     

Note: Tomcat runs as windows service. And MSSQL is configured to windows authentication.

edit: I understand that the native library (DLL) can only be loaded into the JVM once, hence the error, but I after looking around the net I still have no solution.

Muckraker answered 9/1, 2018 at 13:58 Comment(4)
blogs.msdn.microsoft.com/jdbcteam/2007/06/18/…Jacobian
As mentioned in the link, i dnt have a problem with dll version or finding the appropriate path. I can tell this because one of my application connects to MS SQL successfully but the remaining fails. I have even tried to add the lib folder path to shared.loader in catalina.properties.Muckraker
Possible duplicate of JDBC SQLServerException: "This driver is not configured for integrated authentication."Dulcet
When loading tomcat with only a single web application (anyone), the web application successfully connect to the DB. That's the reason i don't think its about versioning.Muckraker
S
3

sqljdbc_auth.dll is need to use windows authentication or Kerberos authentication.

Get the dll from Microsoft and install it either by:

  1. drop on application library folder
  2. drop on the java bin folder.

    Not recommended if you want to package the applications with all the dependencies. Also, it requires to find what java version is being used and from what path.

  3. drop the library on some folder and then add the path in the command line:

    java -Djava.library.path=<library path>...
    

The mssql-jdbc driver and the sqljdbc_auth.dll should be:

  • on the same folder
  • both from the same version
  • for the same architecture (x86/x64) JVM is running.

Check also the jdbc comparability matrix with java versions.

Sonics answered 14/12, 2019 at 0:13 Comment(0)
C
1

The JDBC driver supports the use of Type 2 integrated authentication on Windows operating systems through the integratedSecurity connection string property. To use integrated authentication, copy the sqljdbc_auth.dll file to a directory on the Windows system path on the computer where the JDBC driver is installed.

Alternatively you can set the java.libary.path system property to specify the directory of the sqljdbc_auth.dll. For example, if the JDBC driver is installed in the default directory, you can specify the location of the DLL by using the following virtual machine (VM) argument when the Java application is started:

-Djava.library.path=c:/sqljdbc_<version>/enu/auth/x86

or

-Djava.library.path=c:/sqljdbc_<version>/enu/auth/x64

Please read more about in the original documentation: https://learn.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url?view=sql-server-2017

Constipation answered 1/5, 2018 at 11:16 Comment(0)
R
1

In order to be able to connect with the JDBC, you need to define the connection as follows:

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

Use the following dependency:

       <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>mssql-jdbc</artifactId>
        <version>10.2.0.jre8</version>
       </dependency>
Raspings answered 9/5, 2022 at 11:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.