views:

206

answers:

1

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  A: 

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
codekaizen
Excellent!! Changing my TransactionScope constructor did the trick with no further changes necessary. Thank you.I already had enlist=true in my connection string but I think that I screwed something up posting my XML.
John Prideaux