The purpose of transactions is to ensure that you are not running a session with dirty data or an error. Consider a very simple case of a book order transaction.
You are likely to follow these steps: a) Check if the book currently exists. b) Read the customer information and see if he has anything in the shopping cart. c) Update the number of books d) Make an order entry
Now consider the case when you run an error when entering an order, you want your other changes to be undone, and this is when you roll back the transaction.
How do you do this? Well, there are many ways. One way to use web applications is to track the HTTP Error object as follows:
if(HttpContext.Current != null && HttpContext.Current.Error != null) transaction.Rollback();
Ideally, you should not break your job template with explicit transaction blocks. Try to avoid this as much as possible.
Baz1nga
source share