Can I roll back my db changes. Here is a scenario.
Function 1():- Enters a record in Employee table
Function 2():- Enter a record in customer table
Function 3():- Some Updates to other tables.Emails etc
Q:- If there is an Exception thrown in Function3(), Can I roll back the work done in Function1() and Function2()??
function 1's give new employee id and this new Employee ID is used in 2nd function.
Second function use the New Employee Id, and creates New Customer Id,
Third Function, use both Employee Id, Customer Id and do some emailing part, update entries in other tables.
From here, if in Function3(), any exception occurs, I want New employee Id, and new customer Id, gets deleted.
or If any exception occurs in Function 2, only employee id should be removed.
I CAN NOT CREATE 1 FUNCTION FOR THESE 3 FUNCTIONS, AS IN MY REAL code, THERE IS A LOT OF OTHER WORK GOING ON IN 3 FUNCTIONS.
CAN YOU PLEASE HELP?
Answer:- Which I think will work?
Throw your own exception from function 2 and 3, then accordingly, delete the previous data enteredTry
Dim myEx as new exception("101")
End Try Try
Dim myEx as new exception("102")
main Function from where these 3 are called:
if exception.message= "101"
' Code to delete employee id
else if exception.message= "102"
' Code to delete employee id and code to delete customer id
IS IT THE GOOD APPROACH TO DO THIS ? IS THERE A METHOD LIKE BEGIN TRANS, END TRANS