.net - In C#, how to keep three operation in Transaction? -
currently need 3 operations:
- write data db
- write file remote share folder
- write data acitive directory
how make 3 steps in 1 transaction ?
i google lot, , have 2 plans,
first one. use transactionscope
, code
using (transactionscope scope = new transactionscope()) { this.storeintodb(); this.writeshardfolderdata(); this.storeintoad(); scope.complete(); }
i have no idea, code work or not, need tests that, maybe me
second one, use try-catch, code that:
try{ this.storeintodb(); } catch() { exit(); } try{ this.writeshardfolderdata(); } catch() { this.rollbackdb(); } try{ this.storeintoad(); } catch() { this.rollbackdb(); this.rollbacksharefolderdata(); }
is there other solution scenario ?
Comments
Post a Comment