Using NHibernate with SQLite

104 views
Skip to first unread message

RobertSt...@gmail.com

unread,
Jul 13, 2008, 12:30:01 AM7/13/08
to nhusers
I have been trying to use SQLite with NHibernate, but thus far have
been unsuccessful. I saw Ayende's post on using it here:
http://www.ayende.com/Blog/archive/2006/10/14/7183.aspx

The configuration there did not work for me.

I also tried the configuration in this article:
http://www.ayende.com/Blog/archive/2006/10/14/7183.aspx.

That configuration did not work for me either.

I am using NHibernate 1.2.1 GA. I am also using the
NHibernateFacility from Castle.

Here is my configuration:

<facility
id="nhibernatefacility"

type="Castle.Facilities.NHibernateIntegration.NHibernateFacility,
Castle.Facilities.NHibernateIntegration"
isWeb="true">

<factory id="sessionFactory1">
<settings>


<item
key="hibernate.connection.provider">NHibernate.Connection.DriverConnectionProvider</
item>
<item
key="hibernate.connection.driver_class">NHibernate.Driver.SQLiteDriver</
item>
<item
key="hibernate.connection.connection_string">Data
Source=demo.db;Version=3</item>
<item
key="hibernate.dialect">NHibernate.Dialect.SQLiteDialect</item>
<item
key="hibernate.query.substitutions">true=1;false=0</item>

</settings>
<assemblies>
<assembly>AgCg.Core</assembly>
<assembly>AgCg.ContentManagement</assembly>
</assemblies>
</factory>

</facility>

Is there a SQLite executable or dll I am supposed to have in my bin
folder to get this to work? Do I have to edit the machine.config file
to put in a provider?

Thanks,

Robert

Gustavo Ringel

unread,
Jul 13, 2008, 9:30:55 AM7/13/08
to nhu...@googlegroups.com
take a look at this here he configures castle facilities for sqlite and nh search.

http://gschuager.blogspot.com/2008/04/nhibernatesearch-with.html

pieter

unread,
Jul 13, 2008, 5:12:56 PM7/13/08
to nhusers
Do you have the ADO.NET provider for SQLite? Download it from
http://sourceforge.net/project/showfiles.php?group_id=94056. And of
course SQLite. Just drop the assemblies in your bin and it should all
work.

Here is the configuration that I use.

facility NHibernateFacility:
configuration:
@isWeb = isWeb, defaultFlushModel = 'Commit'
factory:
@id = 'nhibernate.factory'
settings(keymap):
dialect = 'NHibernate.Dialect.SQLiteDialect'
connection.provider =
'NHibernate.Connection.DriverConnectionProvider'
connection.driver_class = 'NHibernate.Driver.SQLiteDriver'
connection.connection_string = 'Data
Source=unit_test.db;Version=3;New=True;'
relativeExpiration = 30
assemblies = [ mappingAssembly ]

(using Binsor)

Hope it helps

On Jul 13, 5:30 am, "RobertStackho...@gmail.com"

Jason Meckley

unread,
Jul 14, 2008, 10:28:54 AM7/14/08
to nhusers
if you're using sqlite for testing you can set the Data
Source=:memory: when using this mode make sure to set the ReleaseMode
to OnClose

On Jul 13, 5:12 pm, pieter <schutte.pie...@gmail.com> wrote:
> Do you have the ADO.NET provider for SQLite? Download it fromhttp://sourceforge.net/project/showfiles.php?group_id=94056. And of
> > key="hibernate.connection.provider">NHibernate.Connection.DriverConnectionP­rovider</
> > item>
> >                              <item
> > key="hibernate.connection.driver_class">NHibernate.Driver.SQLiteDriver</
> > item>
> >                              <item
> > key="hibernate.connection.connection_string">Data
> > Source=demo.db;Version=3</item>
> >                              <item
> > key="hibernate.dialect">NHibernate.Dialect.SQLiteDialect</item>
> >                              <item
> > key="hibernate.query.substitutions">true=1;false=0</item>
>
> >          </settings>
> >          <assemblies>
> >            <assembly>AgCg.Core</assembly>
> >            <assembly>AgCg.ContentManagement</assembly>
> >          </assemblies>
> >        </factory>
>
> >      </facility>
>
> > Is there a SQLite executable or dll I am supposed to have in my bin
> > folder to get this to work?  Do I have to edit the machine.config file
> > to put in a provider?
>
> > Thanks,
>
> > Robert- Hide quoted text -
>
> - Show quoted text -

Paul Batum

unread,
Jul 15, 2008, 12:28:27 PM7/15/08
to nhusers
Hi Robert,

I am not sure if this will help at all or not, but I recently ran into
some troubles with SQLite that have since been resolved. I found that
two important factors are:

1. Whether you are specifying the correct driver class for the dll you
are using. That is, whether your driver class config is this:
<item key="connection.driver_class">NHibernate.Driver.SQLiteDriver</
item>
or this:
<item key="connection.driver_class">NHibernate.Driver.SQLite20Driver</
item>

The first version refers to the old deprecated library:
http://sourceforge.net/project/showfiles.php?group_id=94056
While the second version refers to the current library:
http://sourceforge.net/project/showfiles.php?group_id=132486

You specifically asked about whether you are supposed to put a dll
into your bin folder. Yes, you must. Be sure to use the driver setting
that corresponds to the version of the library you choose to use.

2. Be aware that if you are running on a x64 machine using AnyCPU or
x64 config and trying to use the x86 version of System.Data.SQLite.DLL
you will run into problems. This caught me by surprise when I tried to
work from home and run my unit tests (32-bit environment at work, 64-
bit at home).

Hope it helps,

Paul Batum

On Jul 13, 5:30 am, "RobertStackho...@gmail.com"
<RobertStackho...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages