我有以下代码示例:
static void Main(string[] args)
{
TransactionManager.DistributedTransactionStarted += (sender, eventArgs) =>
{
Console.WriteLine("Promoted to distributed transaction!");
};
?
const string connectionString = @"Server=localhost\SQLEXPRESS;Database=master;Integrated Security=true;";
?
using (var tx = new TransactionScope())
using (var conn1 = new SqlConnection(connectionString))
using (var conn2 = new SqlConnection(connectionString))
{
conn1.Open();
Console.WriteLine("conn1 opened");
?
conn2.Open();
Console.WriteLine("conn2 opened");
?
tx.Complete();
}
?
Console.ReadLine();
?
}
Run Code Online (Sandbox Code Playgroud)
在 .NET Framework (4.8) 控制台应用程序(针对 SQL Server Express 2017)中执行此代码时,会产生以下输出:
由于事务被提升为分布式事务,我希望一个类似的面向 .NET Core (3.0) 的控制台应用程序会抛出一个
System.PlatformNotSupportedException(此平台不支持分布式事务。)。
但是,实际输出是:
为什么是这样?我希望将事务提升为分布式事务是与框架无关的。
编辑:这个 .NET …