Rolling back

Thread is closed for posting
5 posts, 0 answers
  1. Steve
    Steve avatar
    1888 posts
    Member since:
    Dec 2008

    Posted 18 Aug 2010 Link to this post

    What's the proper syntax for a rollback?

    RTOHelper.RTOScope.Transaction.Begin();
     try {
      //Change Things
                RTOHelper.RTOScope.Transaction.Commit();
            }catch (Exception ex){
                    RTOHelper.RTOScope.Transaction.Rollback();
            }

    This is what I've been doing, but when an exception hits it tells me no Active Transaction... (I can do the check for IsActive...but is that how it's done?  When will it ever be active?
  2. IT-Als
    IT-Als avatar
    381 posts
    Member since:
    Sep 2008

    Posted 19 Aug 2010 Link to this post

    Hi Steve,

    You are on the right path. Do the check for IsActive on the transaction before doing the Rollback in your catch block. I do this all the time in my code.

    I can't remember the cases where you will end up with an inactive transaction.

    Regards

    Henrik
  3. Petko_I
    Admin
    Petko_I avatar
    184 posts

    Posted 19 Aug 2010 Link to this post

    Hello Steve,

    Whenever you call scope.Transaction.Begin() you start an active transaction.  The other way to start a transaction is to start it implicitly when the scope.TransactionProperties.AutomaticBegin is set to true. It is active until the scope.Transaction.Commit() is called. When an exception occurs before the Commit method is invoked you still have the Transaction active and you can rollback it safely in the catch block. In case the exception occurs during the commit operation we internally rollback the transaction – so when the catch block code is executed the transaction is inactive. Therefore, it is a good practice to check the status of the transaction before rolling it back.

    I hope this information will wipe the confusion. If you want to understand the reason for the exception in your case, please provide the full code.

    Best wishes,
    Petko_I
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Steve
    Steve avatar
    1888 posts
    Member since:
    Dec 2008

    Posted 19 Aug 2010 Link to this post

    Hey Petko,
      That's actually where my question arose from funnily enough...the exception was happening BEFORE the commit, and then dumping into the catch and I get an exception...I figured it wasn't a big deal because I CAN check for Active, and if I haven't committed anything there wasn't anything to rollback...?

    Steve
  5. Petko_I
    Admin
    Petko_I avatar
    184 posts

    Posted 23 Aug 2010 Link to this post

    Hello Steve,

    Closing the transaction when an exception occurs before the commit operation is something that should not happen in general. We would like to further investigate the cause of your problem. Can you provide the code that generates the exception and sends you to the catch block? Regardless of the reason for the error you receive, checking whether the transaction is active is always recommended.

    Thanks in advance for your time. I hope to hear from you soon.


    All the best,
    Petko_I
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top