针对 Azure SQL DB 的 WCF 事务 [英] WCF Transaction against Azure SQL DB

查看:45
本文介绍了针对 Azure SQL DB 的 WCF 事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试针对 Azure SQL DB 进行 WCF 事务,但迄今为止证明未成功.下面是一个例子:

I am trying to make a WCF Transaction against an Azure SQL DB which is proving to be unsuccessful so far. Here is an example:

using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
{
      try
      {
             ServiceReference1.Service1Client proxy1 = new ServiceReference1.Service1Client();
             proxy1.UpdateData();
             ServiceReference2.Service1Client proxy2 = new ServiceReference2.Service1Client();
             proxy2.UpdateData();
             ts.Complete();
      }
      catch (Exception ex)
      {
             ts.Dispose();
      }
}

UpdateData() 实现如下所示:

Where UpdateData() implementation looks like this:

[OperationBehavior(TransactionScopeRequired = true)]
public void UpdateData()
{
     SqlConnection objConnection = new SqlConnection(strConnection);
     objConnection.Open();
     SqlCommand objCommand = new SqlCommand("INSERT INTO[Security].[Tenants] VALUES(3, 'test', '2016-04-14 14:20:00", objConnection);
     objCommand.ExecuteNonQuery();
     objConnection.Close();
}

发生的事情是在 connection.Open() 上抛出异常:在 System.Transactions.Transaction.GetPromotedToken()

What happens is on connection.Open() an exception is thrown: Object reference not set to instance of an object at at System.Transactions.Transaction.GetPromotedToken()

如果我尝试在没有事务范围的情况下或在同一服务中的事务范围内执行此操作,它会成功执行.只有当我尝试在 WCF 事务中执行它时才会出现问题.

If I try to execute this without a transaction scope or in a transaction scope in the same service it is executed successfully. The problem occurs only if I try executing it in a WCF Transaction.

推荐答案

我怀疑问题在于 WCF 事务依赖于 Azure 中本机不支持的分布式事务协调器.

I suspect the issue is that WCF transactions rely on the Distributed Transaction Coordinator which is not supported natively in Azure.

SQL Azure 中对分布式事务的唯一支持是更新的 SQL 原生弹性事务,支持作为 .NET 4.6.1 的一部分引入:

The only support for distributed transactions in SQL Azure are newer, SQL-native elastic transactions, with support introduced as part of .NET 4.6.1:

SQL Azure 弹性事务

这篇关于针对 Azure SQL DB 的 WCF 事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆