开发者

Informix .NET Provider and TransactionScope not rolling back

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.CommandTe开发者_Go百科xt = "insert into table_ (code_, description) values ('JEP', 'Test')";
                int count = cmd.ExecuteNonQuery();
            }
        }
        if (commitIndicator)
        {
        }
        else
        {
            throw new Exception("planned failure");
        }
        tscope.Complete();
    }
}

Connection Strings:


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜