在收到NHibernate提交事务后,提交事务请求没有相应的BEGIN事务。”

时间:2022-03-14 02:31:06

I use Transaction scope for distributed transactions and NHibernate inner transactions. After all operations I check if Transaction.Current is not aborted and try to commit NHibernate transaction.

我对分布式事务和NHibernate内部事务使用事务范围。在所有操作之后,我检查是否有事务。未中止Current并尝试提交NHibernate事务。

Sometimes I receive this error:

有时我收到这样的错误:

The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION. The transaction active in this session has been committed or aborted by another session.

提交事务请求没有相应的BEGIN事务。此会话中的活动事务已被另一个会话提交或中止。

With the following stacktrace:

使用下面的异常堆栈:

System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) в System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) в System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) в System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) в System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest) в System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest) в System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest, String name, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest) в System.Data.SqlClient.SqlInternalTransaction.Commit() в System.Data.SqlClient.SqlTransaction.Commit() в NHibernate.Transaction.AdoTransaction.Commit().

System.Data.SqlClient.SqlConnection。OnError(SqlException异常,布尔breakConnection)вSystem.Data.SqlClient.SqlInternalConnection。OnError(SqlException异常,布尔breakConnection)вSystem.Data.SqlClient.TdsParser。ThrowExceptionAndWarning(TdsParserStateObject stateObj)вSystem.Data.SqlClient.TdsParser。运行(RunBehavior RunBehavior,SqlCommand cmdHandler,SqlDataReader dataStream数据,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)вSystem.Data.SqlClient.TdsParser。TdsExecuteTransactionManagerRequest(Byte[]缓冲区,TransactionManagerRequestType请求,字符串transactionName TransactionManagerIsolationLevel isoLevel,Int32超时,SqlInternalTransaction事务,TdsParserStateObject stateObj,布尔isDelegateControlRequest)вSystem.Data.SqlClient.SqlInternalConnectionTds。ExecuteTransactionYukon(TransactionRequest TransactionRequest、字符串transactionName IsolationLevel iso,SqlInternalTransaction internalTransaction,布尔isDelegateControlRequest)вSystem.Data.SqlClient.SqlInternalConnectionTds。ExecuteTransaction(TransactionRequest TransactionRequest、字符串名称IsolationLevel iso,SqlInternalTransaction internalTransaction,布尔isDelegateControlRequest)вSystem.Data.SqlClient.SqlInternalTransaction.Commit()вSystem.Data.SqlClient.SqlTransaction.Commit()вNHibernate.Transaction.AdoTransaction.Commit()。

The main problem that this error is occasional. What could be the reason for this?

这个错误的主要问题是偶然的。为什么会这样呢?

1 个解决方案

#1


0  

looks like you are not opening your sesions through a centralized code but closing the session transaction every time, else i dont see a reason for this happening..

看起来您不是通过集中的代码打开您的sesions,而是每次都关闭会话事务,否则我看不出发生这种情况的原因。

make sure you have the same code path that is being used at the location where this error is thrown.. probably looking at the stack trace.

确保在抛出错误的位置使用相同的代码路径。可能是在查看堆栈跟踪。

#1


0  

looks like you are not opening your sesions through a centralized code but closing the session transaction every time, else i dont see a reason for this happening..

看起来您不是通过集中的代码打开您的sesions,而是每次都关闭会话事务,否则我看不出发生这种情况的原因。

make sure you have the same code path that is being used at the location where this error is thrown.. probably looking at the stack trace.

确保在抛出错误的位置使用相同的代码路径。可能是在查看堆栈跟踪。