-
July 25th, 2006, 09:26 AM
#1
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?");
}
-
August 1st, 2006, 06:24 AM
#2
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.
kings4u
-
August 1st, 2006, 10:39 AM
#3
Update
Just an update,
I was never able to get the .net transactionscopes to work. From the following article
http://blogs.msdn.com/angelsb/archiv...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.
-
August 2nd, 2006, 07:14 AM
#4
Re: TransactionScope !@#$
thanks dbui for your reply ..
I followed some of the steps but I am not able to make it ..
thank you once again
kings4u
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|