多个同时连接点网核心



我想在我的 dotnet 核心项目中将 TransactionScope 用于我的业务服务。 我同时使用MysqlConnection和SqlConnection。 我的目的是添加一些我自己的数据库的数据,并对客户端数据库执行一些操作。

using TransactionScope scope = new TransactionScope();
var addDatabase = await _databaseRepository.AddDatabase(mappedEntity);
await _realDbService.CreateDatabaseOnRemote(dto);
scope.Complete();

这是我服务的代码示例。 每个存储库都执行自己的 crud 操作。 我试图关闭已经完成的连接。

但是我有一个错误,即当前不支持多个同时连接或在同一事务中具有不同连接字符串的连接。

感谢您的评论。

我使用了解决此问题的解决方案,但我不确定它是最佳解决方案。

我使用了 Transaction.Current.TransactionDone 事件 如果事务完成,那么我调用我的方法内联一个范围。

using TransactionScope scope = new TransactionScope();
addDatabaseResult = await _databaseRepository.AddDatabase(mappedEntity);
Transaction.Current.TransactionCompleted += delegate
{
using TransactionScope scopeInline = new TransactionScope();
_realDbService.CreateDatabaseOnRemote(dto);
scopeInline.Complete();
};
scope.Complete();

最新更新