Click here to Skip to main content
15,939,736 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi All,

I have two web forms and two different tables for save data of these two web forms,
on first web form i have a hyperlink which is used to redirect to second page from first page . Now when i click on hyperlink page i save the data of first page in first table now when i click on save of second page if second page insertion failed i want to rollback first insertion i.e., made on first page
for insertion i simple made a stored procedure.

how to rollback insertion..

Thanks in Advance...
Posted
Updated 10-Apr-11 18:25pm
v2

There are two ways I can think of:

1. Do Transaction management in the application. Create a connection and begin transaction in the form1. Now use the same connection object in the form2. If the save in form2 works well, do a commit. Or else do a rollback. Be sure to take care of closing and disposing connection object. If one opens the connection in page 1 and does the save. Then goes to page 2 and just closes the window. Your connection must get closed and transaction must get rolled back.

2. You can do transaction in your stored procedure. In the application, when user moves from page1 to page2, just keep the data in the Session. When the user clicks on save, save all the data in one DB hit. Here is how your application would work:

Page1 -> Page2: Save data in the Session
Page2.Save: Get Page1 and Page2 data and end it to DB.
In your stored procedure:

1. Main SP called
2. Begin tansaction
3. Execute SP to save Page1 data
4. Execute SP to save Page2 data
5. Commit or rollback
6. Return output to page2
 
Share this answer
 
Hi,

If I understood your problem correctly, you're trying to do the transaction in two parts, having a user conversation in between. This should never be done.

When a transaction starts, you simply make the necessary modifications, check for errors etc and in the end, commit or rollback. Having any kind of UI operations in the middle will cause locking related problems etc.

So my advice is that when the user changes to second page, store the necessary data somewhere else (session etc) and when the user finally presses the save, make necessary validity checks against all data and save the data in a single, short, transaction.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900