Informix .NET Provider 和 TransactionScope 不回滚

发布于 2024-08-18 15:50:26 字数 1475 浏览 5 评论 0原文

我有一个小型概念验证分布式事务应用程序,它正在对两个表执行简单的插入操作——一个是 MS SQL Server 表,另一个是 Informix Dynamic Server 表。当抛出异常时,问题就来了。如果我使用 Informix 的 OLE DB 驱动程序,一切都会正常工作——两个插入都会回滚;如果我使用 Informix 的 .NET 数据提供程序,Informix 插入不会回滚。

有人对发生的事情有任何想法吗?

在代码片段中,您会注意到注释掉的 EnlistTransaction() 方法。当显式调用时,我收到一个异常,表明该方法未实现。

代码片段:

private void doTransaction(Boolean commitIndicator)
{
    using (TransactionScope tscope = new TransactionScope())
    {
        using (SqlConnection cn = new SqlConnection { ConnectionString = sql2008Settings.ConnectionString })
        {
            cn.Open();

            using (SqlCommand cmd = cn.CreateCommand())
            {
                cmd.CommandText = "insert into uom (uom) values ('Test')";
                int count = cmd.ExecuteNonQuery();
            }
        }
        using (IfxConnection cn = new IfxConnection())
        {
            cn.ConnectionString = idnSettings.ConnectionString;
            cn.Open();
            //cn.EnlistTransaction(Transaction.Current);
            using (IfxCommand cmd = cn.CreateCommand())
            {
                cmd.CommandText = "insert into table_ (code_, description) values ('JEP', 'Test')";
                int count = cmd.ExecuteNonQuery();
            }
        }
        if (commitIndicator)
        {
        }
        else
        {
            throw new Exception("planned failure");
        }
        tscope.Complete();
    }
}

连接字符串:

I have a little proof-of-concept distributed transaction application that is doing a simple insert into two tables -- one a MS SQL Server table, the other an Informix Dynamic Server table. The problem comes when an exception is thrown. If I use the OLE DB driver for Informix, everything works fine -- both inserts roll back; if I use the .NET Data Provider for Informix, the Informix insert does not roll back.

Does anyone have any ideas as to what is going on?

In the code snippet, you will notice the commented-out EnlistTransaction() method. When explicitly called, I get an exception indicating that the method is not implemented.

Code snippet:

private void doTransaction(Boolean commitIndicator)
{
    using (TransactionScope tscope = new TransactionScope())
    {
        using (SqlConnection cn = new SqlConnection { ConnectionString = sql2008Settings.ConnectionString })
        {
            cn.Open();

            using (SqlCommand cmd = cn.CreateCommand())
            {
                cmd.CommandText = "insert into uom (uom) values ('Test')";
                int count = cmd.ExecuteNonQuery();
            }
        }
        using (IfxConnection cn = new IfxConnection())
        {
            cn.ConnectionString = idnSettings.ConnectionString;
            cn.Open();
            //cn.EnlistTransaction(Transaction.Current);
            using (IfxCommand cmd = cn.CreateCommand())
            {
                cmd.CommandText = "insert into table_ (code_, description) values ('JEP', 'Test')";
                int count = cmd.ExecuteNonQuery();
            }
        }
        if (commitIndicator)
        {
        }
        else
        {
            throw new Exception("planned failure");
        }
        tscope.Complete();
    }
}

Connection Strings:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傻比既视感 2024-08-25 15:50:26

我非常确定 Informix .Net ADO Provider 不支持 TransactionScope。这不是 ADO.Net 提供商的要求。

您可以通过使用 COM+ 和 MSDTC 来实现这一点,因为 Informix 确实支持这一点。您需要执行以下操作:

  • 将“enlist=true”添加到连接字符串
  • EnterpriseServicesInteropOption.Full 添加到 TransactionScope 构造函数

I'm pretty sure that the Informix .Net ADO Provider doesn't support TransactionScope. It's not a requirement of an ADO.Net provider.

You might get this to work by using COM+ and MSDTC, since the Informix does support that. You'll need to do the following:

  • Add "enlist=true" to your connection string
  • Add EnterpriseServicesInteropOption.Full to your TransactionScope constructor
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文