在ASP.NET Core 2应用程序中,使用TransactionScope不支持注册环境事务。

5

在TransactionScope中打开sql连接时,会出现"Enlisting in Ambient transactions is not supported"错误。我正在使用asp.net core 2应用程序中的ado.net。

        using (var ts = new TransactionScope())
        {
            try
            {
                Connection.Open();
                repository.Insert(entity);                    
                ts.Complete();
            }

            catch (Exception ex)
            {
                ts.Dispose();
            }
            finally
            {
                Connection.Close();
            }
        }
2个回答

8
如果你在使用 .Net Standard 时遇到这个问题,你可以添加最新版本的 System.Data.SqlClient 引用,这个问题就会消失。

确认了,我正在使用 .Net Core 2.2,并在项目中安装了最新的 NuGet 包 System.Data.SqlClient(写作时为4.8.0),修复了 SQL 访问代码的问题。 - David Gunderson

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接