繁体   English   中英

MS DTC 使用 Entity Framework Core 取消事务

[英]MS DTC Cancelling Transaction with Entity Framework Core

我收到一个

System.Data.SqlClient.SqlException (0x80131904):Microsoft 分布式事务协调器 (MS DTC) 已取消分布式事务。

使用 EF Core 2.1 时出错。 完整的堆栈跟踪位于此消息的底部。

下面是基本过程:

  1. 读取来自 Kafka 的请求消息
  2. 将消息写入 SQL Server 上的一组“原始”表
  3. 调用从原始表读取消息、验证传入数据、转换数据中的几个字段并写入一组“生产”表的存储过程。
  4. 从生产表中检索转换后的请求。
  5. 通过主要由微服务组成的编排来处理请求,随着编排取得进展,将更新保存回生产表。

MSDTC 错误在第 3 步间歇性地发生,但经常发生。第 2 步和第 3 步中的原始表和生产表位于同一 SQL Server 上的不同数据库中。 作为第 5 步的一部分,还调用了一个单独的 SQL Server,但我得到的唯一错误是第 3 步中的 MSDTC 取消。

我知道 .NET Core 不支持 MSDTC,但我不确定为什么这个过程的任何部分都被提升为 MSDTC。 我没有任何显式事务,并且通过 appsettings 中的 ConnectionStrings 为每个数据库标准化了连接字符串。

任何见解表示赞赏。

authAPI.usp_AuthTransform @CorrelationID, @AuthStateID OUT, @CorrelationSeqID OUT

System.Data.SqlClient.SqlException (0x80131904): The Microsoft Distributed Transaction Coordinator (MS DTC) has cancelled the distributed transaction.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.CompleteAsyncExecuteReader()
   at System.Data.SqlClient.SqlCommand.EndExecuteNonQueryInternal(IAsyncResult asyncResult)
   at System.Data.SqlClient.SqlCommand.EndExecuteNonQuery(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteAsync(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues, CancellationToken cancellationToken)
ClientConnectionId:24a868f2-3f00-4e07-92fd-7537beb23d33
Error Number:1206,State:118,Class:18
Exception thrown: 'System.Data.SqlClient.SqlException' in System.Private.CoreLib.dll
Exception thrown: 'System.Data.SqlClient.SqlException' in System.Private.CoreLib.dll
'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.1.15\System.IO.MemoryMappedFiles.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
nH.AuthRequestIntake.nHDischarge.ReceiveHandler:Error: 353c5648-5ef0-44b9-bd5b-ac1395243ac6-System.Data.SqlClient.SqlException (0x80131904): The Microsoft Distributed Transaction Coordinator (MS DTC) has cancelled the distributed transaction.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.CompleteAsyncExecuteReader()
   at System.Data.SqlClient.SqlCommand.EndExecuteNonQueryInternal(IAsyncResult asyncResult)
   at System.Data.SqlClient.SqlCommand.EndExecuteNonQuery(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteAsync(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlCommandAsync(DatabaseFacade databaseFacade, RawSqlString sql, IEnumerable`1 parameters, CancellationToken cancellationToken)
   at nH.AuthRequestIntake.Domain.AuthRequestReceivedEventHandler`2.TransformToAuthRequestAsync(AuthRequest rawRequest, IIncomingDbContext dbContext) in C:\Users\scott.carter\source\repos\authrequestintake\nH.AuthRequestIntake.Domain\AuthRequestReceivedEventHandler.cs:line 170
   at nH.AuthRequestIntake.Domain.AuthRequestReceivedEventHandler`2.HandleAsync(IDomainEvent domainEvent) in C:\Users\scott.carter\source\repos\authrequestintake\nH.AuthRequestIntake.Domain\AuthRequestReceivedEventHandler.cs:line 68
ClientConnectionId:24a868f2-3f00-4e07-92fd-7537beb23d33
Error Number:1206,State:118,Class:18

System.Data.SqlClient.SqlException (0x80131904): The Microsoft Distributed Transaction Coordinator (MS DTC) has cancelled the distributed transaction.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.CompleteAsyncExecuteReader()
   at System.Data.SqlClient.SqlCommand.EndExecuteNonQueryInternal(IAsyncResult asyncResult)
   at System.Data.SqlClient.SqlCommand.EndExecuteNonQuery(IAsyncResult asyncResult)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteAsync(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.ExecuteSqlCommandAsync(DatabaseFacade databaseFacade, RawSqlString sql, IEnumerable`1 parameters, CancellationToken cancellationToken)
   at nH.AuthRequestIntake.Domain.AuthRequestReceivedEventHandler`2.TransformToAuthRequestAsync(AuthRequest rawRequest, IIncomingDbContext dbContext) in C:\Users\scott.carter\source\repos\authrequestintake\nH.AuthRequestIntake.Domain\AuthRequestReceivedEventHandler.cs:line 170
   at nH.AuthRequestIntake.Domain.AuthRequestReceivedEventHandler`2.HandleAsync(IDomainEvent domainEvent) in C:\Users\scott.carter\source\repos\authrequestintake\nH.AuthRequestIntake.Domain\AuthRequestReceivedEventHandler.cs:line 68
ClientConnectionId:24a868f2-3f00-4e07-92fd-7537beb23d33
Error Number:1206,State:118,Class:18```



结果证明这是一条红鲱鱼。 我在某处读到 MSDTC 问题有时会掩盖其他问题,并建议进行数据库跟踪。 果然,跟踪显示临时表在负载下跨连接被删除,所以我们现在正在努力解决这个问题。

感谢所有阅读并考虑问题的人!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM