Informix .NET Provider and TransactionScope not rolling back

跟風遠走 提交于 2019-12-11 05:56:22

问题


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:


回答1:


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


来源:https://stackoverflow.com/questions/2111507/informix-net-provider-and-transactionscope-not-rolling-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!