2009-09-23

Using NHibernate and SQLite on x64

If you are using a x64 OS, and have a reference to System.Data.SQLite and NHibernate throws exceptions like these:

  • NHibernate.HibernateException : Could not create the driver from NHibernate.Driver.SQLite20Driver, NHibernate, Version=2.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
  • NHibernate.HibernateException : The IDbCommand and IDbConnection implementation in the assembly System.Data.SQLite could not be found. Ensure that the assembly System.Data.SQLite is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.

It most likely because SQLite is not a managed dll, it is compiled to a specific CPU.

System.Data.SQLite does not change this behavior since it is just a wrapper and container for the unmanaged dll.

The easiest way to fix this is to change the platform target under build properties of the Visual Studio project to x86.

VSProjectPropertiesBuild

Another alternative is to choose the x64 version of System.Data.SQLite, but if the same source code is used on both x86 and x64 it is not option.

1 comment:

Anonymous said...

hello,
plz don't do that!
deploy sqlite ado.net provider with your project (download it from s.f.) and it will install the right version based on the current CPU architecture.