From: Date: May 11 2007 5:51pm Subject: Connector/NET commit: r712 - in branches/5.0: . Driver/Source TestSuite/Source List-Archive: http://lists.mysql.com/commits/26495 X-Bug: 26754 Message-Id: <200705111551.l4BFp9wC028409@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/5.0/CHANGES branches/5.0/Driver/Source/Connection.cs branches/5.0/TestSuite/Source/Transactions.cs Log: Bug #26754 EnlistTransaction throws false MySqlExeption "Already enlisted" Fixed this by exiting out of EnlistTransaction if the passed transaction is null. Also, fixed a similar problem by only setting currentTransaction after the enlist has happened without an exception. Modified: branches/5.0/CHANGES =================================================================== --- branches/5.0/CHANGES 2007-05-10 21:13:29 UTC (rev 711) +++ branches/5.0/CHANGES 2007-05-11 15:51:08 UTC (rev 712) @@ -12,6 +12,7 @@ Bug #27668 FillSchema and Stored Proc with an out parameter Bug #28167 Poor performance building connection string (thanks Maxim!) Bug #26041 Connection Protocol Property Error in PropertyGrid Control + Bug #26754 EnlistTransaction throws false MySqlExeption "Already enlisted" Other changes ------------- Modified: branches/5.0/Driver/Source/Connection.cs =================================================================== --- branches/5.0/Driver/Source/Connection.cs 2007-05-10 21:13:29 UTC (rev 711) +++ branches/5.0/Driver/Source/Connection.cs 2007-05-11 15:51:08 UTC (rev 712) @@ -269,6 +269,10 @@ /// public override void EnlistTransaction(System.Transactions.Transaction transaction) { + // if the transaction given to us is null, then there is nothing to do. + if (transaction == null) + return; + if (currentTransaction != null) { if (currentTransaction.BaseTransaction == transaction) @@ -277,15 +281,16 @@ throw new MySqlException("Already enlisted"); } - currentTransaction = new MySqlPromotableTransaction(this, transaction); - transaction.EnlistPromotableSinglePhase(currentTransaction); + MySqlPromotableTransaction t = new MySqlPromotableTransaction(this, transaction); + transaction.EnlistPromotableSinglePhase(t); + currentTransaction = t; } #endif /// public new MySqlTransaction BeginTransaction() { - return this.BeginTransaction(IsolationLevel.RepeatableRead); + return BeginTransaction(IsolationLevel.RepeatableRead); } /// @@ -477,7 +482,6 @@ /// public override void Close() { - //TODO: rollback any pending transaction if (State == ConnectionState.Closed) return; if (dataReader != null) Modified: branches/5.0/TestSuite/Source/Transactions.cs =================================================================== --- branches/5.0/TestSuite/Source/Transactions.cs 2007-05-10 21:13:29 UTC (rev 711) +++ branches/5.0/TestSuite/Source/Transactions.cs 2007-05-11 15:51:08 UTC (rev 712) @@ -27,32 +27,32 @@ namespace MySql.Data.MySqlClient.Tests { - [TestFixture] - public class Transactions : BaseTest - { - [TestFixtureSetUp] - public void FixtureSetup() - { - Open(); + [TestFixture] + public class Transactions : BaseTest + { + [TestFixtureSetUp] + public void FixtureSetup() + { + Open(); - execSQL("DROP TABLE IF EXISTS Test"); - createTable("CREATE TABLE Test (key2 VARCHAR(1), name VARCHAR(100), name2 VARCHAR(100))", "INNODB"); - } + execSQL("DROP TABLE IF EXISTS Test"); + createTable("CREATE TABLE Test (key2 VARCHAR(1), name VARCHAR(100), name2 VARCHAR(100))", "INNODB"); + } - [TestFixtureTearDown] - public void FixtureTeardown() - { - Close(); - } + [TestFixtureTearDown] + public void FixtureTeardown() + { + Close(); + } #if NET20 - void TransactionScopeInternal(bool commit) + void TransactionScopeInternal(bool commit) { MySqlConnection c = new MySqlConnection(GetConnectionString(true)); MySqlCommand cmd = new MySqlCommand("INSERT INTO test VALUES ('a', 'name', 'name2')", c); - try + try { using (TransactionScope ts = new TransactionScope()) { @@ -191,5 +191,73 @@ Assert.Fail(ex.Message); } } + + /// + /// Bug #26754 EnlistTransaction throws false MySqlExeption "Already enlisted" + /// + [Test] + public void EnlistTransactionNullTest() + { + try + { + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + cmd.Connection.EnlistTransaction(null); + } + catch { } + + using (TransactionScope ts = new TransactionScope()) + { + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + try + { + cmd.Connection.EnlistTransaction(Transaction.Current); + } + catch (MySqlException) + { + Assert.Fail("No exception should have been thrown"); + } + } + } + + /// + /// Bug #26754 EnlistTransaction throws false MySqlExeption "Already enlisted" + /// + [Test] + public void EnlistTransactionWNestedTrxTest() + { + MySqlTransaction t = conn.BeginTransaction(); + + using (TransactionScope ts = new TransactionScope()) + { + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + try + { + cmd.Connection.EnlistTransaction(Transaction.Current); + } + catch (InvalidOperationException) + { + /* caught NoNestedTransactions */ + } + } + + t.Rollback(); + + using (TransactionScope ts = new TransactionScope()) + { + MySqlCommand cmd = new MySqlCommand(); + cmd.Connection = conn; + try + { + cmd.Connection.EnlistTransaction(Transaction.Current); + } + catch (MySqlException) + { + Assert.Fail("No exception should have been thrown"); + } + } + } } }