Michael Hedgpeth
Michael Hedgpeth

Reputation: 7862

How to configure SQLite to run with NHibernate where assembly resolves System.Data.SQLite?

I am using the latest NHibernate 2.1.0Beta2. I'm trying to unit test with SQLite and have the configuration set up as:

        Dictionary<string, string> properties = new Dictionary<string, string>();
        properties.Add("connection.driver_class", "NHibernate.Driver.SQLite20Driver");
        properties.Add("dialect", "NHibernate.Dialect.SQLiteDialect");
        properties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
        properties.Add("query.substitutions", "true=1;false=0");
        properties.Add("connection.connection_string", "Data Source=test.db;Version=3;New=True;");
        properties.Add("proxyfactory.factory_class",
                       "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu");

        configuration = new Configuration();
        configuration.SetProperties(properties);

When I try to run it, I get the following error:

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.
at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName) in c:\CSharp\NH\nhibernate\src\NHibernate\Driver\ReflectionBasedDriver.cs: line 26
at NHibernate.Driver.SQLite20Driver..ctor() in c:\CSharp\NH\nhibernate\src\NHibernate\Driver\SQLite20Driver.cs: line 28 

So it looks like I need to reference the assembly directly. How would I do this so I don't get this error anymore?

I downloaded the latest assembly from here: http://sourceforge.net/projects/sqlite-dotnet2.

Upvotes: 8

Views: 12255

Answers (4)

Julien B&#233;rub&#233;
Julien B&#233;rub&#233;

Reputation: 1266

I had the same problem, and the above solutions didn't work out for me. I think System.Data.SQLite has changed since.

Note that this problem is specific to a case respecting all of the following criteria:

  • using SQLite
  • with System.Data.SqlLite
  • on an x64 machine
  • and NHibernate (2.1.2.4 in my case)

That chunk of config in my web.config (or app.config for my unit tests) got it to work. I had to qualify the assembly to be sure he loads correctly.

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <qualifyAssembly 
        partialName="System.Data.SQLite" 
        fullName="System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=AMD64" />
    </assemblyBinding>
  </runtime>
</configuration>

Somewhere in it's inner plumbing, during the mapping using scanned assemblies, NHibernate creates an Assembly object using it's partial name, as a string, "System.Data.SQLite". Somehow, the x86 version of the assembly got loaded.

The above configuration made sure that using the partial name to load an assembly would provide the x64 version.

Upvotes: 3

mr0zek
mr0zek

Reputation: 73

If you don't want to use 64bit version of System.Data.Sqlite You can change "platform target" (in visual studio project->properties->Build) to x86.

Upvotes: 3

Ben Foster
Ben Foster

Reputation: 34800

After adding the reference to the System.Data.SQLite assembly, I had to set copy local to true (select the assembly reference in VS and go to properties) so that the assembly is copied to the bin directory.

Upvotes: 6

Jared Harley
Jared Harley

Reputation: 8337

Are you running 64-bit Windows?

When looking around Google, I saw several posts commenting that the SQLite dll file is built for x86, not x64.

See this post: http://codetripper.wordpress.com/2009/01/03/using-sqlite-on-vista-64-bit/

Edit: I'm not sure as of when, but I noticed today that the latest releases of System.Data.SQLite include the x64 dll. The x64 .dll is in \bin\x64.

http://sqlite.phxsoftware.com/

Upvotes: 12

Related Questions