Bug #22528 TransactionScope does not work in 5
Submitted: 20 Sep 2006 18:07 Modified: 21 Jan 2014 23:02
Reporter: [ name withheld ] Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:5 OS:Windows (Windows XP)
Assigned to: CPU Architecture:Any

[20 Sep 2006 18:07] [ name withheld ]
Description:
Given the post here:

http://forums.mysql.com/read.php?38,103186,111238#msg-111238

I tried MySQL Connector/NET 5.0.0 and it did not work. The following test case fails in the Assert, where there is still 1 record in the database (I can verify this by looking directly at the database).

I believe this is a bug since I can switch to SQL Server with the same test case and everything works properly.

        [Test]
        public void SimpleTransaction()
        {
            string tableName = "test" + new Random(unchecked((int)DateTime.UtcNow.Ticks)).Next(1, 1000);

            try
            {
                // Create a test database
                using (IDbConnection conn = RDBMSLayer.DBConnect())
                {
                    RDBMSLayer.ExecuteNonQuery(conn, "create table " + tableName + " (id int not null primary key)");
                }
                using (TransactionScope scope = Base.CreateTransactionScope())
                {
                    using (IDbConnection conn2 = RDBMSLayer.DBConnect())
                    {
                        int rowsInserted = RDBMSLayer.ExecuteNonQuery(conn2, "insert into " + tableName + " (id) values (1)");
                        Assert.AreEqual(1, rowsInserted);

                        // Now throw a random exception
                        if (rowsInserted == 1)
                        {
                            throw new TestException();
                        }
                    }
                }
            }
            catch (TestException)
            {
                using (IDbConnection conn = RDBMSLayer.DBConnect())
                {
                    Assert.AreEqual(0, RDBMSLayer.GetRowCount(conn, tableName));
                }
            }
            finally
            {
                using (IDbConnection conn = RDBMSLayer.DBConnect())
                {
                    RDBMSLayer.ExecuteNonQuery(conn, "drop table " + tableName);
                }
            }
        }

How to repeat:
Run the test provided.
[21 Sep 2006 14:16] [ name withheld ]
I went under the assumption that MySqlConnection simply wasn't auto-enlisting in the enclosing transaction, and so I tried to manually enlist a new connection when I created it; however, this did not work.

                Transaction currentTransaction = Transaction.Current;
                if (currentTransaction != null &&  retConnection is MySqlConnection)
                {
                    // MySQL does not support auto-enlist yet
                    retConnection.EnlistTransaction(currentTransaction);
                }
[30 Sep 2006 10:11] Tonci Grgin
Hi.
I will quote Reggie on this:
"5.0.0 supports TransactionScope. It does not yet support upgrading transactions to full MSDTC scope. We are working on supporting this in the 5.0.2 release."
[30 Sep 2006 14:14] [ name withheld ]
I don't believe this has anything to do with MSDTC, this is not a distributed transaction, but a simple local transaction on the same data source. If 5.0.0 supports TransactionScope, then I imagine this is a bug. Perhaps my setup is just wrong, but I have tried many options, and I cannot get a simple, *local* TransactionScope to work...

Thanks