TransactionScope抛出异常。我正在使用ASP.NET Core和Core 3.0。
在Windows本地机器上,我会遇到以下问题:“此平台不支持分布式事务。”
我想要将两个数据库同步,并希望使用TransactionScope在两个数据库中获得一致的状态。
当我将其部署到使用AppService和Azure Sql的Azure中时,它可以正常工作。
通常,当我检查具有.net core 3.0的此链接时,它应该可以正常工作。 https://learn.microsoft.com/de-de/dotnet/api/system.transactions.transactionscope?view=netcore-3.0
希望有人能帮助我。
using (var scope = new TransactionScope())
{
-- database1
using (SqlConnection connection = new SqlConnection(connectionString_DB1))
{
using (System.Data.SqlClient.SqlCommand cmd = connection.CreateCommand())
{
....
connection.Open();
result = cmd.ExecuteNonQuery();
}
}
--database2
using (SqlConnection connection = new SqlConnection(connectionString_DB2))
{
using (System.Data.SqlClient.SqlCommand cmd = connection.CreateCommand())
{
....
connection.Open();
result = cmd.ExecuteNonQuery();
}
}
scope.Complete();
}