javasql-serverwebsphere-libertysqljdbc

WAS Liberty: sqljdbc driver not configured for integrated authentication


I have a problem with the database connection when migrating a web application from Tomcat 6 to WAS Liberty 8.5.5.8.

On WAS Liberty I get the following error:

com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication

I have placed "sqljdbc4.jar" inside the applications WEB-INF\lib-folder. I have tried placing the file "sqljdbc_auth.dll" various places, like the applications WEB-INF\lib-folder, the WAS Liberty bin folder, the WAS Liberty lib folder. But none of it solves my problem.

On Tomcat I had placed "sqljdbc4.jar" inside the Tomcat lib folder and "sqljdbc_auth.dll" inside the Tomcat bin folder and then it works.

I'm suspecting that I'm placing the "sqljdbc_auth.dll" file in the wrong place, but I can't figure out where else to place it. I haven't been able to find anything online that specifies where to place the file on WAS Liberty.


Solution

  • First of all, I recommend that you use a DataSource for your application instead of a raw JDBC driver. By using a DataSource (which are container managed when configured on an application server) you will benefit from many inherent optimizations done by the application server, such as connection pooling and transaction support.

    Note that a DataSource is not specific to WAS Liberty, in any app server you will get higher performance at a lower development cost by using a container managed DataSource instead of a raw JDBC drivers.


    To configure a DataSource:

    Configure the DataSource and JDBC library in the server.xml:

    <!-- Enable JDBC and JNDI features (at least) -->
    <featureManager>
        <feature>jdbc-4.1</feature>
        <feature>jndi-1.0</feature>
    </featureManager>
    
    <dataSource id="MyDataSource" jndiName="jdbc/MyDataSource">
        <jdbcDriver libraryRef="MSJDBCLib"/>
        <properties.microsoft.sqlserver databaseName="SAMPLEDB" serverName="localhost" portNumber="1433"/>
    </dataSource>
    
    <library id="MSJDBCLib">
        <fileset dir="C:/path/to/sqljdbc4.jar"/>
    
        <!-- To have authentication support, add the dll to the library -->
        <fileset dir="C:/path/to/sqljdbc_auth.dll"/>
    </library>
    

    See IBM doc: Configuring database connectivity in Liberty

    The key to answering your question is to add the <fileset> element pointing to the auth dll file in your <library> element like this:

    <!-- To have authentication support, add the dll to the library -->
    <fileset dir="C:/path/to/sqljdbc_auth.dll"/>
    

    To use a DataSource:

    Before, you probably did something like this:

    String connectionURL = "jdbc:sqlserver://localhost:1433;DatabaseName=YourDBName;user=UserName;Password=YourPassword";
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    Connection con = DriverManager.getConnection(connectionUrl);
    

    With DataSources, you can inject them or look them up using JNDI:

    Inject:

    @Resource(lookup = "jdbc/MyDataSource")
    DataSource myDataSource;
    
    ...
    
    Connection con = myDataSource.getConnection();
    

    JNDI Lookup:

    DataSource myDataSource = new InitialContext().lookup("jdbc/MyDataSource");
    Connection conn = myDataSource.getConnection();