I wrote a Java package which connects to a SQL Server database using JDBC and integrated security. This package runs just as intended from my Java IDE. Now I’m trying to access some classes in this package from a separate .NET app using IKVM.
However, now I’m getting an ExceptionInInitializerError in the .NET app, and the stack trace shows that this error occurs during the database connection initialization.
I created an app.config file for the .NET app to add the JDBC driver to the Java library path using:
<add key="ikvm:java.library.path" value="C:\Microsoft JDBC Driver 4.0 for SQL Server\sqljdbc_4.0\enu\auth\x64"/>
I tried altering the \x64 to \x86 (using the 32-bit auth dll rather than the 64-bit), and I received the exact same error, which I thought was odd. Then I removed this line from the app.config and received a “Failed to load the sqljdbc_auth.dll” warning with a “This driver is not configured for integrated authentication.” SQLServerException.
I migrated the database connection code over into VB.NET/IKVM and recreated the original error using these four lines:
Dim connectionUrl As String = "jdbc:sqlserver://db\instance;integratedsecurity=true"
Dim driver As String = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
java.sql.DriverManager.registerDriver(New com.microsoft.sqlserver.jdbc.SQLServerDriver())
Dim dbConn As java.sql.Connection = java.sql.DriverManager.getConnection(connectionUrl)
So, I’m pretty sure that, if I can get these four lines working, my problem should be solved. Anybody have any ideas? Thanks in advance!
The way to track down what’s going on is to print the exception (to the console) using the Java Throwable.printStackTrace() method. That way you get the underlying cause.
My guess is that tThis will show that the problem is that you forgot to copy ikvm-native-win32-x86.dll (or ikvm-native-win32-x64.dll) to your application directory.