c# - Saga 完成导致 Distributed Transaction Completed 错误

标签 c# database nservicebus distributed-transactions saga

处理顺序:

  • Saga 消息处理程序收到包含数据项的第一条消息。
  • 消息处理程序使用具有自己的数据库事务的业务对象。
  • 如果项目更新正常,数据库事务提交并且 saga 完成。
  • Saga 消息处理程序接收包含数据项的第二条消息。
  • 消息处理程序抛出异常,尝试打开新的数据库事务,如上所示。

错误信息:

System.Data.SqlClient.SqlException (0x80131904): Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.

堆栈跟踪:

2012-01-27 14:07:47,407 [Worker.9] ERROR 

LawCover.LISServices.LISBankAgent.SagaMessageHandler [(null)] - Exception details
System.Data.SqlClient.SqlException (0x80131904): Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   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.SqlInternalConnection.BeginSqlTransaction(IsolationLevel iso, String transactionName)
   at System.Data.SqlClient.SqlConnection.BeginTransaction(IsolationLevel iso, String transactionName)
   at System.Data.SqlClient.SqlConnection.BeginTransaction()
   at LawCover.LIS.DataAccess.ConnectionManager.BeginTransaction()
   at LawCover.LISServices.LISBankAgent.LISMethods.AddCreditCardPaymentSettlementScheduleItemsAndReceiptsIntoLISForCurrentMessages(BankResponseFileProcessed message) in C:\Projects\LIS Improvements\LIS\Source\LISServices\LISBankAgent\LISMethods.cs:line 53
   at LawCover.LISServices.LISBankAgent.SagaMessageHandler.Handle(BankResponseFileProcessed message) in C:\Projects\LIS Improvements\LIS\Source\LISServices\LISBankAgent\SagaMessageHandler.cs:line 177

上面的流程有很多代码,但我很乐意发布有用的代码。

最佳答案

我剥离了事务,发现 saga 处理程序正在打开另一个数据库连接,默认情况下,该连接已登记在 DTC 中。我在连接字符串中添加了“Enlist=false”,因为需要捕获并相应地处理数据库抛出的异常,而不是破坏分布式事务。现在它的行为符合预期。

感谢您的意见,我将重新审视代码并采纳您的意见。

关于c# - Saga 完成导致 Distributed Transaction Completed 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9058504/

相关文章:

php - 在 SQL 语句中使用 PHP 变量

c# - NServiceBus - 如何在消息信封中传递自定义 header ?

c# - 静态类和多个同时请求

c# - "default"通用约束有什么作用?

c# - 更改 System.Dynamic.ExpandoObject 默认行为

c# - 如何从我的 mono for android 应用程序中获取网络文件列表?

sql - 未授权的访问独占锁 block 访问共享锁

mysql - 数据库设计: Difference between using boolean fields and duplicate tables

c# - 使用NServiceBus时,MVVM中的ObservableCollection不变

NServiceBus: "ArgumentNullException"被 NServiceBus 抛出