Mandar Shinde

Mandar Shinde

  • NA
  • 423
  • 114.8k

Nested transactions using C#

Dec 2 2019 3:46 AM
Dear All,
I hope you are doing well. I am facing problem which is related to nested trasactions.
 
eg. :-
 
  1.  MySqlConnection connection= new MySqlConnection(ConnectionString);  
  2. MySqlTransaction myTrans = null;  
  3. connection.Open();  
  4. myTrans = connEpion.BeginTransaction();  
  5. try{  
  6.  InsertOperation ....  
  7. string result = InsertOperation2 ....  
  8. myTrans.Committ();  
  9. }  
  10. catch(Exception ex)  
  11. {  
  12. Console.Write(ex.Message);  
  13. }finally  
  14. {  
  15. connection.Close();  
  16. }  
InsertOperation2 is a function which is returning string result either exception or anything.
If I got any error then all insert operations should get rollback including operation which is performed in a method.
If I won't  committ transaction then it will not save any data and Once if I commiitt any transaction then I am not able to rollback to it.
Thanking you in advance.
Regards. 
 

Answers (2)