开发者

sqlite inmemory + castle-activerecord = No transaction is active on this connection

I am using sqlite in memory db ( connection string is: Data Source=:memory:;Version=3;New=True;) + Castle ActiveRecord, using C#

The DB access code looks like this:

using(TransactionScope())
{
    // do ActiveRecord objects modifications
}

When transaction is going to be disposed/commited, the folowing exception is appears:

NHibernate.TransactionException occurred
  Message="Commit failed with SQL exception"
  Source="NHibernate"
  StackTrace:
       at NHibernate.Transaction.AdoTransaction.Commit()
  InnerException: System.Data.SQLite.SQLiteException
       Message="Library used incorrectly\r\nNo transaction is active on this connection"
       Source="System.Data.SQLite"
       ErrorCode=-2147467259
       StackTrace:
            at System.Data.SQLite.SQLiteTransaction.IsValid(Boolean throwError) in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteTransaction.cs:line 166
            at System.Data.SQLite.SQLiteT开发者_StackOverflowransaction.Commit() in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteTransaction.cs:line 67
            at NHibernate.Transaction.AdoTransaction.Commit()

As far as I understood the problem coming from sqlite "autocommit" mode. In source code of System.Data.SQlite I have found the following lines:

if (_cnn._transactionLevel == 0 || _cnn._sql.AutoCommit == true)
{
_cnn._transactionLevel = 0; // Make sure the transaction level is reset before returning
if (throwError == true) throw new SQLiteException((int)SQLiteErrorCode.Misuse, "No transaction is active on this connection");
else return false;
}

How can I properly setup sqlite connection to use ActiveRecord/Nhibernate TransactionScope ? (turn off autocommit? something else?)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜