sqlite inmemory + castle-activerecord =此连接上没有活动的事务

时间:2011-08-31 09:41:43

标签: nhibernate sqlite castle-activerecord transactionscope

我在内存中使用sqlite db(连接字符串是:Data Source =:memory :; Version = 3; New = True;)+ Castle ActiveRecord,使用C#

数据库访问代码如下所示:

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

当要处理/提交交易时,会出现以下异常:

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.SQLiteTransaction.Commit() in c:\dev\sqlite\dotnet\System.Data.SQLite\SQLiteTransaction.cs:line 67
            at NHibernate.Transaction.AdoTransaction.Commit()

据我所知,问题来自sqlite“autocommit”模式。在System.Data.SQlite的源代码中,我找到了以下几行:

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;
}

如何正确设置sqlite连接以使用ActiveRecord / Nhibernate TransactionScope? (关闭自动提交?还有其他什么?)

0 个答案:

没有答案