I have a WinForms application that interacts with a SqlCe local
database. I manage db operations using BindingSources, TableAdapters
and typed datasets.I have several operations scattered through several
methods in two different classes that I need to perform in a
transaction and I was thinking of using System.Transactions.Transaction or CommitableTransaction. My question is, do Transaction or CommittableTransaction
work in such situations? For example, would this code work successfully in a
transaction and rollback in an error or do I have to also use transaction in OtherClass methods too?:
| OtherClassothercls=newOtherClass(); |
| ... |
|
| privatevoidDoAll() |
| { |
| /*begintransactionhere*/ |
| this.tableAdapter.DoSomeDBWork(); |
| othercls.DeleteSomeRecords();//usestableadapter+sqlcodetodelete.throwsexceptiononerror.doesn'thavetransaction |
| othercls.DeletOtherRecords();//usestableAdapter.Rows.Find(id).Delete().throwsexceptiononerror.doesn'thavetransaction |
| othercls.Update();//usestableadapter.Update().throwsexceptiononerror.doesn'thavetransaction |
| this.DeleteSomeFiles();//throwsexceptiononfail |
| /*endtransactionhere*/ |
| } |