- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这篇文章的基本问题是:“为什么未经提倡的LTM交易会受到质疑?”
我收到System.Transactions.TransactionInDoubtException,我无法解释原因。不幸的是,我无法重现此问题,但根据跟踪文件确实会发生。我正在使用SQL 2005,连接到一个数据库并使用一个SQLConnection,所以我不希望升级。错误消息指示超时。但是,有时我会收到超时消息,但异常(exception)是事务已中止而不是不确定,这更容易处理。
这是完整的堆栈跟踪:
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()
Any ideas? Why am i getting in doubpt and what should i do when i get it?
EDIT for more information
I actually still don't have the answer for this. What I did realize is that the transaction actually partially commits. One table gets the insert but the other does not get the update. The code is HEAVILY traced and there is not much room for me to be missing something.
Is there a way I can easily find out if the transaction has been promoted. Can we tell from the stack trace if it is? SIngle Phase commit (which is in the strack trace) seems to indicate no promotion to me, but maybe i'm missing something. If its not getting promoted then how can it be in doubt.
Another interesting piece to the puzzle is that i create a clone of the current transaction. I do that as a workarround to this issue. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=914869&SiteID=1
Unfortunately, i don't know if this issue has been resolved. Maybe creating the clone is causing a problem. Here is the relevant code
using (TransactionScope ts = new TransactionScope())
{
transactionCreated = true;
//part of the workarround for microsoft defect mentioned in the beginning of this class
Transaction txClone = Transaction.Current.Clone();
transactions[txClone] = txClone;
Transaction.Current.TransactionCompleted += new TransactionCompletedEventHandler(TransactionCompleted);
MyTrace.WriteLine("Transaction clone stored and attached to event");
m_dataProvider.PersistPackage(ControllerID, package);
MyTrace.WriteLine("Package persisted");
m_dataProvider.PersistTransmissionControllerStatus(this);
MyTrace.WriteLine("Transmission controlled updated");
ts.Complete();
}
最佳答案
当前公认的答案是,毫无疑问,LMT(非MSDTC)交易不会引起任何疑问。经过对类似问题的大量研究,我发现这是不正确的。
由于实现了单阶段提交协议(protocol)的方式,在事务管理器向其下属发送SinglePhaseCommit请求之后,在下属回复已提交/中止/或准备(需要升级/升级为MSDTC)消息。如果在这段时间内连接丢失,则说明事务“有疑问”,b/c TransactionManager在要求下属执行SinglePhaseCommit时从未收到响应。
从MSDN Single-Phase Commit,也可以在此答案的底部看到“单阶段提交流”图像:
There is a possible disadvantage to this optimization: if the transaction manager loses contact with the subordinate participant after sending the Single-Phase Commit request but before receiving an outcome notification, it has no reliable mechanism for recovering the actual outcome of the transaction. Consequently, the transaction manager sends an In Doubt outcome to any applications or voters awaiting informational outcome notification
关于c# - 在SQL Server 2005上使用System.Transactions的TransactionInDoubtException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/983035/
我有一些简单的 SELECT 语句和一个 INSERT 包裹在 using(TransactionScope...) block 中。更新:隔离级别为 ReadCommited 我在调用 scope.
我正在以下面的方式使用事务范围, var option1 = new TransactionOptions(); option1.IsolationLevel = IsolationL
我有 2 个作业在 Sql Server 数据库中读取和生成数据。每隔一段时间,作业就会因 System.Transactions.TransactionInDoubtException 崩溃。确切的
以下代码是我的业务层的一部分: public void IncrementHits(int ID) { using (var context = new MyEntiti
我是一名优秀的程序员,十分优秀!