TransactionScope !@#$
Hello everyone,
I'm using NET 2.0 developing in C# connecting to a Mysql database with ADO.net (MySQL Connector/Net -- Mysql.data.MySqlClient). I want to use the new TransactionScope methods to control my transactions, but I'm not having much luck.
Can anyone tell me why the following code won't rollback? I thought all i had to do was NOT call complete().
-Dan
using (TransactionScope ts = new TransactionScope())
{
string connectionString = ConfigurationManager.AppSettings["DATABASECONNECTIONSTRING"];
MySqlConnection mySqlConnection = new MySqlConnection(connectionString);
mySqlConnection.Open();
MySqlCommand mySqlCommand = new MySqlCommand();
mySqlCommand.Connection = mySqlConnection;
mySqlCommand.CommandText = @"INSERT INTO tablename VALUES
('one', 'two', 'three');";
mySqlCommand.ExecuteNonQuery();
mySqlConnection.Close();
throw new Exception("why won't you roll back?");
}
[1046 byte] By [
dbui] at [2007-11-19 23:56:27]

# 1 Re: TransactionScope !@#$
hi!
did u chect whether the connection is opened or not?
I also have the same problem, but the error occurs while opening the connection.
If you found some answer please inform.
# 2 Re: TransactionScope !@#$
Just an update,
I was never able to get the .net transactionscopes to work. From the following article
http://blogs.msdn.com/angelsb/archive/2004/07/07/175586.aspx
My understanding was that when you bracket code inside of a transaction scope, any connections that are instantiated within the scope would automatically detect that there was a transaction scope around it, and would then automatically register and enlist itself within the transaction.
This never happened, and was unable to find any resources to explain why. I ended up implementing the transactions the old way and associating the connections to the transactions manually.
Something along the lines of :
MySqlConnection mySqlConnection = new MySqlConnectionConfigurationManager.AppSettings["DATABASECONNECTIONSTRING"]);
mySqlConnection.Open();
MySqlTransaction trans = conn.BeginTransaction();
// do work with the connection
// trans.commit or trans.rollback
mySqlConnection.Close();
The only answer I have is that perhaps there the mysql connector that I was using did not support this behavior. Eventually, I would like to test with SQLserver, to see if I can get it to work there.
dbui at 2007-11-10 3:31:23 >
