CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2006
    Posts
    2

    Angry 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?");

    }

  2. #2
    Join Date
    Jul 2005
    Location
    Bremen, Germany
    Posts
    33

    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

  3. #3
    Join Date
    Jul 2006
    Posts
    2

    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.

  4. #4
    Join Date
    Jul 2005
    Location
    Bremen, Germany
    Posts
    33

    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
  •  





Click Here to Expand Forum to Full Width

Featured