This is a migrated thread and some comments may be shown as answers.

Rolling back

4 Answers 48 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
sitefinitysteve asked on 18 Aug 2010, 05:30 PM
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?

4 Answers, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 19 Aug 2010, 11:39 AM
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
0
Petko_I
Telerik team
answered on 19 Aug 2010, 05:05 PM
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
0
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
answered on 19 Aug 2010, 05:08 PM
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
0
Petko_I
Telerik team
answered on 23 Aug 2010, 04:18 PM
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
Tags
General Discussions
Asked by
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Answers by
IT-Als
Top achievements
Rank 1
Petko_I
Telerik team
sitefinitysteve
Top achievements
Rank 2
Iron
Veteran
Share this question
or