如何处理TransactionInDoubtException如何处理、TransactionInDoubtException

由网友(夜夜做新郎)分享简介:我有一些简单的 SELECT 语句和插入裹在使用(的TransactionScope ...)块。更新:隔离级别ReadCommited 我得到了下面的异常上调用 scope.Complete()。(见下文)同时数据库是造成完全另一个应用程序在高负载下。 事实后,我发现,插入声明没有实际上执行。 我的问题是:如何...

我有一些简单的 SELECT 语句和插入裹在使用(的TransactionScope ...)块。更新:隔离级别ReadCommited 我得到了下面的异常上调用 scope.Complete()。(见下文)同时数据库是造成完全另一个应用程序在高负载下。 事实后,我发现,插入声明没有实际上执行。 我的问题是:如何处理这个异常的方式,离开我的数据库保持一致的状态?

我在找的那个总是完成或没有完成,从来没有一半的交易。

异常堆栈跟踪:

  System.Transactions.TransactionInDoubtException:本次交易是个疑问。 ---> System.Data.SqlClient.SqlException:在超时过期。之前完成操作已过或服务器超时期间没有响应。
   在System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection)
   在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   在System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj,UInt32的错误)
   在System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult,TdsParserStateObject stateObj)
   在System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()
   在System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
   在System.Data.SqlClient.TdsParserStateObject.ReadByte()
   在System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand的cmdHandler,SqlDataReader的数据流,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)
   在System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(字节[]缓冲区,TransactionManagerRequestType要求,串transactionName,TransactionManagerIsolationLevel ISOLEVEL,的Int32超时,SqlInternalTransaction交易,TdsParserStateObject stateObj,布尔isDelegateControlRequest)
   在System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest,串transactionName,IsolationLevel将异,SqlInternalTransaction internalTransaction,布尔isDelegateControlRequest)
   在System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest,字符串名称的IsolationLevel异,SqlInternalTransaction internalTransaction,布尔isDelegateControlRequest)
   在System.Data.SqlClient.SqlDelegatedTransaction.SinglePhaseCommit(SinglePhaseEnlistment入伍)
   ---内部异常堆栈跟踪的结尾---
   在System.Transactions.TransactionStateInDoubt.EndCommit(InternalTransaction TX)
   在System.Transactions.CommittableTransaction.Commit()
   在System.Transactions.TransactionScope.InternalDispose()
   在System.Transactions.TransactionScope.Dispose()
 

解决方案

一个交易有疑问时,它的未知是否已完成或中止。该数据库仍处于一致的状态。如果你得到这样的异常,则需要访问数据库,以找出是否改变已经发生或没有,但你可以确信,你不会看到的变化一半。

文化企业看过来 宁波疫情防控惠企政策一网通办,补贴补助一站申领

请注意,我不知道如果有疑问的部分是DTC会发生什么,和你有一个分布式事务 - 我当然希望微软考虑到了这一点,而且可疑分布式事务仍被视为一个整体。

下面请参见:具体而言,该交易的最终结果,无论是提交或中止,是从来不知道这个交易

i have some simple SELECT statements and an INSERT wrapped in a using(TransactionScope...) block. UPDATE: isolation level is ReadCommited i got the following exception on calling scope.Complete().(see below) At the same time the database was under high load caused by another application entirely. After the fact i found that the INSERT statement did in fact execute. My question is: How do i handle this exception in a way that leaves my database in a consistent state ?

i`m looking for a transaction that is always either completed or not completed and never half done.

Exception stack trace:

System.Transactions.TransactionInDoubtException: The transaction is in doubt. ---> System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
   at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()
   at System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
   at System.Data.SqlClient.TdsParserStateObject.ReadByte()
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest, String name, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlDelegatedTransaction.SinglePhaseCommit(SinglePhaseEnlistment enlistment)
   --- End of inner exception stack trace ---
   at System.Transactions.TransactionStateInDoubt.EndCommit(InternalTransaction tx)
   at System.Transactions.CommittableTransaction.Commit()
   at System.Transactions.TransactionScope.InternalDispose()
   at System.Transactions.TransactionScope.Dispose()

解决方案

A transaction is in doubt when it's unknown whether it has been completed or aborted. The database is still in a consistent state. If you ever get such an exception, you need to access the database to figure out whether the changes has taken place or not, but you can be sure you won't see half of the changes.

Note, I don't know what happens if the component in doubt is the DTC, and you have a distributed transaction - I sure hope Microsoft took care of that, and that a doubtful distributed transaction is still treated as a whole.

See here: "Specifically, the final outcome of the transaction, whether it commits or aborts, is never known for this transaction."

阅读全文

相关推荐

最新文章