ClassNotFoundException thrown in IKVM.Runtime.dll for JDBC

User 8604712a60

01-10-2010 20:14:52

Hello,


I'm new to ChemAxon software and am modifying the JChemBaseSearch example found in the "JChem .NET API 5.3.8.9" directory. I made a few modifications to the code to use the installed JDBC drivers and our db connection parameters. I'm able to connect to our SQL Server database through the Microsoft JDBC SQL Server driver from the other Marvin and JChem applications but when I attempt to connect through the JChemBaseSearch .Net application I get a class not found error even through the path to the jdbc jar file is in the ClassPath environment variable.


I also attempted to initiate the load through this call



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



but got the following error.


"A first chance exception of type 'java.lang.ClassNotFoundException' occurred in IKVM.Runtime.dll"


Any guidance would be greatly appreciated.


Thanks,


Molly


 


 


 


 


 


 

ChemAxon b62f37c21a

04-10-2010 12:22:46

Hello Molly,


Please see this example: http://www.chemaxon.com/dotNET/examples/jchem/JChemBaseSearch/DataAccess.cs.html


Unfortunately Class.forName() is not as simple in .NET as in Java, because of the strong named assemblies. Instead, we use something like this:


DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());

Hope this helps,


Gabor Vasko

User 8604712a60

04-10-2010 14:36:12










gvasko wrote:

Hello Molly,


Please see this example: http://www.chemaxon.com/dotNET/examples/jchem/JChemBaseSearch/DataAccess.cs.html


Unfortunately Class.forName() is not as simple in .NET as in Java, because of the strong named assemblies. Instead, we use something like this:


DriverManager.registerDriver(new com.microsoft.sqlserver.jdbc.SQLServerDriver());

Hope this helps,


Gabor Vasko



Thanks, I tried that initially but I'm getting an error on the driver name at compile time saying the type or namespace is not recognized. Is there some other place to reference or register the driver? I have the full path to the sqljdbc.jar file in the CLASSPATH now.

ChemAxon b62f37c21a

04-10-2010 15:26:17

Two possible solutions:


1/ Try to use JTDS driver which has already been provided with the installer (recommended).


2/ Try to convert the jar file with ikvmc.exe (Program Files/ChemAxon/JChem .NET API ... folder): ikvmc -out:sqljdbc.dll -target:library sqljdbc.jar


After that the dll should be referenced from your project.


We encountered some problems in the past using the MS driver, that is why we provide the JTDS driver.


Classpath: Jar files cannot be used from .NET wihtout the conversion.


Gabor Vasko


sqljdbc.jars

User 8604712a60

04-10-2010 19:21:50










gvasko wrote:

Two possible solutions:


1/ Try to use JTDS driver which has already been provided with the installer (recommended).


2/ Try to convert the jar file with ikvmc.exe (Program Files/ChemAxon/JChem .NET API ... folder): ikvmc -out:sqljdbc.dll -target:library sqljdbc.jar


After that the dll should be referenced from your project.


We encountered some problems in the past using the MS driver, that is why we provide the JTDS driver.


Classpath: Jar files cannot be used from .NET wihtout the conversion.


Gabor Vasko


sqljdbc.jars


I was able to get option 2 to work using sqljdbc4.jar as the source. I had to remove and then add references to the existing IKVM assemblies to avoid a version conflict issue that occurred when I added the reference to the sqljdbc4.dll but everything works now. Thank you!

ChemAxon b62f37c21a

07-10-2010 13:42:57

Thank you for your response.

User 8604712a60

10-06-2011 20:21:16

Hello,


I downloaded the most recent .Net examples (JChem_NET_API_5_5_0_1510) and opened the JChemBaseSearch example. I added a reference to the jtds-1.2.2.dll but when I compile, I get the following error: Found conflicts between different versions of the same dependent assembly. (the details are copied in below.)


Note: Via JCMan.exe, I can connect to a SQL Server 2008 with the following driver connection string: com.microsoft.sqlserver.jdbc.SQLServerDriver.


However, when I try the jtds driver in Visual Studio or, if I use a sqljdbc4.dll generated using ikvmc.exe from the target library of the same driver jar file referenced in the jcman connection string above, I get a similar conflict error message.


Any suggestions would be much appreciated.


Thanks, Molly


*************************************************************************************************************


error CS1705: Assembly 'jtds-1.2.2, Version=5.5.0.1510, Culture=neutral, PublicKeyToken=d25ce09139c726a9' uses 'IKVM.OpenJDK.Core, Version=0.42.1.72, Culture=neutral, PublicKeyToken=d25ce09139c726a9' which has a higher version than referenced assembly 'IKVM.OpenJDK.Core, Version=0.42.1.42, Culture=neutral, PublicKeyToken=d25ce09139c726a9'


error CS1705: Assembly 'jtds-1.2.2, Version=5.5.0.1510, Culture=neutral, PublicKeyToken=d25ce09139c726a9' uses 'IKVM.OpenJDK.Jdbc, Version=0.42.1.72, Culture=neutral, PublicKeyToken=d25ce09139c726a9' which has a higher version than referenced assembly 'IKVM.OpenJDK.Jdbc, Version=0.42.1.42, Culture=neutral, PublicKeyToken=d25ce09139c726a9'


c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3247: Found conflicts between different versions of the same dependent assembly.

ChemAxon bd13b5bd77

12-06-2011 18:15:32

Dear Molly,


next Monday is a bank Holiday, on Tuesday Gabor will take a look at the issue.


 


Viktor

ChemAxon b62f37c21a

14-06-2011 11:32:43

Dear Molly,


 


Could you please check what versions of JChem .NET API are installed on your machine?


I suppose there are multiple installations, however, it should work.


Please try to remove and add all JChem .NET API assembly references.


 


Best regards,


Gabor Vasko

ChemAxon 0e37943a96

17-06-2011 07:30:16

Hi Molly,


we could reproduce the problem, when having multiple versions of JChem .NET API present on the machine. Please also verify if the GAC contains any older versions.


1. Go to C:\Windows\assembly


2. Verify the following dlls:


IKVM.* should be 0.42.1.72


JChem should be 5.5.0.150


jtds-1.2.2 should be 5.5.0.1510


You can remove unnecessary versions, by right click uninstall.


 


We also look into the problem why it is trying to resolve a different version, than it has referenced, because as Gabor described it should work even with multiple versions installed.


Best regards,


Tamas.


 

User 8604712a60

17-06-2011 13:24:58

Thanks for relaying this information. I'm out of the office this week but will remove previous versions of the ChemAxon .Net API when I return to the office on Monday.


Molly


 

User 8604712a60

21-06-2011 18:02:33

I removed the previous versions of the .Net API and the example compiled and ran as expected. Thanks.