title: sqljdbc_auth.dll already loaded in another classloader
body: <p>I have an RCP application with different plugins. In two of my plugins I need to connect to SQL Server Database using Windows Integrated Authentication.The first one that is loaded works fine but the second one throws the exception:</p>
  
  <pre><code>Native Library sqljdbc_auth.dll already loaded in another classloader
  </code></pre>
  
  <p>My code is </p>
  
  <p>Plugin A -> SqlRead.java</p>
  
  <pre><code>static{
      try {
          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          Class.forName("net.sourceforge.jtds.jdbc.Driver");
      } catch (ClassNotFoundException e) {
        e.PrintStakeTrace();
      }
  }
  
  private Connection openConnection(String connectionString) throws SQLException{
      return DriverManager.getConnection(connectionString);
  }  
  </code></pre>
  
  <p>Plugin B -> Mirror.java</p>
  
  <pre><code>static {
      try {
          Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          Class.forName("net.sourceforge.jtds.jdbc.Driver");
      } catch (ClassNotFoundException e) {
          e.printStackTrace();
      }
      init();
  }
  
  public void run(){
      try {
                  this.source=DriverManager.getConnection(EaDbStringParser.eaDbStringToJdbc(this.sourceString));
                  this.source.setReadOnly(true);              
              } catch (Exception e) {
                  if (logView != null)
                      logView.log(new Status(Status.INFO, symbolicName, "cannot establish connection", e));
              }
  }
  </code></pre>
  
  <p>In both the plugins I have loaded the sqljdbc4.jar in the manifest file under classpath and also the dll </p>
  
  <p>The manifest is as:</p>
  
  <pre><code>  Bundle-ClassPath: .,
    external:$sqljdbc_driver_location$/sqljdbc4.jar
    Bundle-NativeCode: external:$sqljdbc_driver_location$/auth/x86/sqljdbc_auth.dll 
  </code></pre>
  
  <p>In the plugin A it works fine but in plugin B I get the following exception</p>
  
  <pre><code>   com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication. ClientConnectionId:f4ad6643-4d5e-4cfd-9f9f-585af3707186
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667)
  at com.microsoft.sqlserver.jdbc.AuthenticationJNI.&lt;init&gt;(AuthenticationJNI.java:60)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2229)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220)
  at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
  at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
  at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at com.intel.imc.swa.jetdb.mirror.Mirror.run(Mirror.java:163)
  at com.intel.imc.swa.featuremodel.swamodel.mirror.MirrorFeatureModel.run(MirrorFeatureModel.java:59)
  at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
  Caused by: java.lang.UnsatisfiedLinkError: Native Library C:\sqljdbc_4.0\enu\auth\x86\sqljdbc_auth.dll already loaded in another classloader
  at java.lang.ClassLoader.loadLibrary1(Unknown Source)
  at java.lang.ClassLoader.loadLibrary0(Unknown Source)
  at java.lang.ClassLoader.loadLibrary(Unknown Source)
  at java.lang.Runtime.loadLibrary0(Unknown Source)
  at java.lang.System.loadLibrary(Unknown Source)
  at com.microsoft.sqlserver.jdbc.AuthenticationJNI.&lt;clinit&gt;(AuthenticationJNI.java:35)
  ... 14 more
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>Under my Eclipse installation i have </p>
  
  <pre><code>C:/users/uiqbal/Desktop/Eclispe/sqljdbc_auth.dll 
  </code></pre>
  
  <p>The dll is present in this location and also under</p>
  
  <pre><code>C:/sqldriver/enu/auth/x86/sqljdbc_auth.dll
  </code></pre>
  
  <p>if I remove the dll from my eclipse installation then the first time I try to make the connection it fails complaining that no dll is found under java class path. </p>
  
  <p>I created a new plugin and inside the manifest I added</p>
  
  <pre><code> Bundle-NativeCode: external:$sqljdbc_driver_location$/auth/x86/sqljdbc_auth.dll
  </code></pre>
  
  <p>Where    </p>
  
  <pre><code>  $sqljdbc_driver_location = C:/sqldriver/enu
  </code></pre>
  
  <p>when I try to make the connection again using</p>
  
  <pre><code> DriverManager.getConnection(EaDbStringParser.eaDbStringToJdbc(this.sourceString));
  </code></pre>
  
  <p>I get the following error</p>
  
  <pre><code> WARNING: Failed to load the sqljdbc_auth.dll cause : Native Library C:\Users\uiqbal\Desktop\FM_Eclipse\sqljdbc_auth.dll already loaded in another classloader
  </code></pre>
  
  <p>Any idea how can I resolve this issue?</p>