Can't use SQLite with NH 3.2 ?

261 views
Skip to first unread message

Andrei Alecu

unread,
May 22, 2011, 5:38:39 PM5/22/11
to nhu...@googlegroups.com
I can't seem to use SQLite any more with NHibernate 3.2. I get the following exception:

SetUp : FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.


  ----> System.Data.SQLite.SQLiteException : Callback routine requested an abort
Execution was aborted by the user

--SQLiteException
at System.Data.SQLite.SQLiteDataReader.CheckClosed()
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
at NHibernate.Driver.SQLite20Driver.Connection_StateChange(Object sender, StateChangeEventArgs e) in s:\OpenSource\NHibernate\nhibernate\src\NHibernate\Driver\SQLite20Driver.cs: line 55
at System.Data.SQLite.SQLiteConnection.Open()
at NHibernate.Connection.DriverConnectionProvider.GetConnection() in s:\OpenSource\NHibernate\nhibernate\src\NHibernate\Connection\DriverConnectionProvider.cs: line 49
at NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare() in s:\OpenSource\NHibernate\nhibernate\src\NHibernate\Tool\hbm2ddl\SuppliedConnectionProviderConnectionHelper.cs: line 25
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper) in s:\OpenSource\NHibernate\nhibernate\src\NHibernate\Tool\hbm2ddl\SchemaMetadataUpdater.cs: line 43
at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory) in s:\OpenSource\NHibernate\nhibernate\src\NHibernate\Tool\hbm2ddl\SchemaMetadataUpdater.cs: line 17
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) in s:\OpenSource\NHibernate\nhibernate\src\NHibernate\Impl\SessionFactoryImpl.cs: line 172
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in S:\OpenSource\fluent-nhibernate\src\FluentNHibernate\Cfg\FluentConfiguration.cs: line 108

The code in NHibernate.Driver.SQLite20Driver.Connection_StateChange wants to ExecuteNonQuery, but in CheckClosed(), SQLite.NET does this:

 private void CheckClosed()
    {
      if (_command == null)
        throw new InvalidOperationException("DataReader has been closed");

      if (_version == 0)
        throw new SQLiteException((int)SQLiteErrorCode.Abort, "Execution was aborted by the user");

      if (_command.Connection.State != ConnectionState.Open || _command.Connection._version != _version)
        throw new InvalidOperationException("Connection was closed, statement was terminated");
    }


I dug through the SQLite.NET source and I see the following code:

OnStateChange(ConnectionState.Open);
_version++;

So, version starts at 0 and is only incremented after OnStateChange, which is what Connection_StateChange is subscribed to. 


Am I doing something wrong or is this a bug?

Is someone else able to use SQLite with NH 3.2? Unless anyone else got it to work, I can submit a JIRA issue.

Fabio Maulo

unread,
May 23, 2011, 8:25:35 AM5/23/11
to nhu...@googlegroups.com
Considering that SQLite is used in our continuous integration server you may look in some others places before file a JIRA.

Mohamed Meligy

unread,
May 23, 2011, 9:29:42 AM5/23/11
to nhu...@googlegroups.com
Try the configuration mentioned in this post:
http://gurustop.net/blog/2011/05/19/sqlite-database-nuget-package-common-problems-solved/

Not sure if it can help with your problem though. 


Mohamed Meligy
Readify | Senior Developer

M:+61 451 835006 | W: readify.net

Description: Description: Description: Description: rss_16  Description: Description: Description: Description: cid:image003.png@01CAF81D.6A076510  Description: Description: Description: Description: cid:image005.png@01CAF81D.6A076510



On Mon, May 23, 2011 at 10:25 PM, Fabio Maulo <fabio...@gmail.com> wrote:
Considering that SQLite is used in our continuous integration server you may look in some others places before file a JIRA.

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Patrick Earl

unread,
May 23, 2011, 12:08:59 PM5/23/11
to nhusers
Which version of System.Data.SQLite is this? Perhaps it's a recent
change?

Patrick Earl
>     *    if (_version == 0)
>          throw new SQLiteException((int)SQLiteErrorCode.Abort, "Execution was aborted by the user");*

Andrei Alecu

unread,
May 23, 2011, 8:32:16 PM5/23/11
to nhusers
Note: This is an application that was running 3.1 before, and I
recently updated it to the trunk version of 3.2

It definitely didn't work out of the box any more. I had to completely
comment out the Connection_StateChange event, and rebuild NH to get my
application to run.

It's the same SQLite version (1.0.66.00) as before, I believe it's
caused by some recent change in NHibernate and the way I'm creating
the SessionFactory in this particular project.

When I have more time I'll dig some more, but based on the code I
pasted in the first post, I think I have described what the code path
to that exception is, and it seems possible to get in that state.

I'm also using a custom built version of Fluent NHibernate, which I
updated to work with 3.2, so I'm not sure if this is somehow related
to it. The SessionFactory is created via Fluent NHibernate.

Andrei Alecu

unread,
May 23, 2011, 8:39:17 PM5/23/11
to nhusers
Ok, upon further inspection it looks like we were using an older
version of SQLite, after downloading the latest version (which was
from last year anyway), I see that their code has been fixed to call
the StateChange event after version is incremented.

Might want to mention it as a potentially breaking change in the
change log though, that newer SQLite is needed. (we were running
1.0.56.0 I believe)
Reply all
Reply to author
Forward
0 new messages