“弹性数据库事务”可以在Azure功能和/或应用服务中运行吗?

时间:2017-08-15 10:31:55

标签: azure azure-sql-database azure-web-sites azure-functions

跨多个SQL Azure数据库的distributed transactions文档提到运行事务的环境的guest虚拟机操作系统必须具有.NET 4.6.1。这是Azure功能和/或应用服务的情况吗?

2 个答案:

答案 0 :(得分:3)

我刚刚使用以下代码测试了Azure Web App上的分布式事务。如果我在调用scope.Complete之前抛出异常,则事务将回滚并且记录将不会保存到表中。它证明Azure App Services确实支持弹性数据库事务。

using (var scope = new TransactionScope())
{
    using (var conn1 = new SqlConnection(azureSqlConnStrDb1))
    {
        conn1.Open();
        SqlCommand cmd1 = conn1.CreateCommand();
        cmd1.CommandText = string.Format("insert into T1 values(3)");
        cmd1.ExecuteNonQuery();
    }

    using (var conn2 = new SqlConnection(azureSqlConnStrDb2))
    {
        conn2.Open();
        var cmd2 = conn2.CreateCommand();
        cmd2.CommandText = string.Format("insert into T2 values(4)");
        cmd2.ExecuteNonQuery();
    }

    throw new Exception("I am a exception");
    scope.Complete();
}

答案 1 :(得分:1)

App服务(和函数)在.NET 4.7上运行:

enter image description here

(2017年8月)