【问题标题】:Informix .NET Provider and TransactionScope not rolling backInformix .NET 提供程序和 TransactionScope 未回滚
【发布时间】:2010-01-22 02:02:01
【问题描述】:

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

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

在代码 sn-p 中,您会注意到注释掉的 EnlistTransaction() 方法。当显式调用时,我得到一个异常,表明该方法没有实现。

代码sn-p:

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();
    }
}

连接字符串:

【问题讨论】:

    标签: informix transactionscope


    【解决方案1】:

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

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

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

    【讨论】:

    • 太棒了!!更改我的 TransactionScope 构造函数就可以解决问题,无需进一步更改。谢谢你。我的连接字符串中已经有 enlist=true 但我认为我在发布我的 XML 时搞砸了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-05
    • 2011-01-12
    • 2013-07-07
    • 1970-01-01
    相关资源
    最近更新 更多