Java/JDBC – SQL Server – “Integrated Security”

Background

Wanted to go over the steps to take when one needs to connect to a Microsoft SQL Server Instance using Integrated Security.

Outline

  1. Java
    • JDBC
      • JDBC Connecting String
    • Class Path
      • Includes SQL Server JDBC Driver
  2.  System
    • System Path
      • Add [jdbc-sql]\enu\auth\[platform]\

Tasks

Java

JDBC

JDBC Connecting String

Outline
  1. JDBC URL
    • IntegratedSecurity=True
    • authenticationScheme=NativeAuthentication
Syntax

jdbc:sqlserver://{server-name}:{port};IntegratedSecurity=True;authenticationScheme=NativeAuthentication;databaseName={database};

Sample

jdbc:sqlserver://localhost:1433;IntegratedSecurity=True;authenticationScheme=NativeAuthentication;databaseName=sakila;

java Class Path

SQL Server JDBC Driver

Please include your jdbc driver as part of your classpath when you launch your app.

In our case, %_sqlServerJDBCPath%\ sqljdbc_7.0\enu\mssql-jdbc-7.0.0.jre8.jar

 

System Path

Enhance your system path to include the sqljdbc_[version]\enu\auth\x64\ folder.

We are on SQL JDBC Version 7 and our platform is 64-bit.

Our relative path is sqljdbc_7.0\enu\auth\x64.

Code

Sample


set "_libSQLServerAuth_Folder=C:\downloads\Microsoft\SQLServer\jdbc\v7.0.0.0\extract\sqljdbc_7.0\enu\auth\x64\"

set path=%path%;%_libSQLServerAuth_Folder%

Trouble Shooting

Here are a couple of areas that you may stumble upon.

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

Error

Error Image

Error Text


WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path: [C:\Program Files\Java\jdk-11.0.3\bin,
[WARN ] 2019-06-10 12:57:02.390 [main] JdbcEnvironmentInitiator - HHH000342: Could not obtain connection to query metadata : null
[INFO ] 2019-06-10 12:57:02.424 [main] Dialect - HHH000400: Using dialect: org.hibernate.dialect.SQLServerDialect
[WARN ] 2019-06-10 12:57:02.502 [main] SqlExceptionHelper - SQL Error: 0, SQLState: 08S01
[ERROR] 2019-06-10 12:57:02.509 [main] SqlExceptionHelper - This driver is not configured for integrated authentication.
Exception :- Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

Error Explanation

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

Resolution

  1. java.library.path
    • WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
  2. Please include the folder where sqljdbc_auth is located in your system path.

 

Screen Shots

Hibernate

Working

Image -01

References

  1. Microsoft
    • Docs
      • Docs / SQL / Connect / JDBC / Programming Guide for JDBC SQL Driver / Guide articles
        • Building the Connection URL
          Link
    • CSS SQL Server Engineers
      • Adam W. Saxton
        • JDBC: This driver is not configured for integrated authentication
          Link