c# - Nested transaction scope .net -


i'm using sql server 2008 r2 , trying use transactions.

first question transactions in .net , sql server. if have this

try {     var transactionoption = new transactionoptions();     transactionoption.isolationlevel = isolationlevel.readcommitted;     transactionoption.timeout = transactionmanager.maximumtimeout;      using (var scope = new transactionscope(transactionscopeoption.requiresnew, transactionoption)) {         //create question creates new question in database         helpers.createquestionbankitem(ref mappedoldnewquestionitemguid, missingquestionbankitems);         //question created          //query database code of newly inserted question, database give me code since complete has not been called yet?                scope.complete();     } } catch (exception ex) {     throw; }  //query database code of newly inserted question,  database give me code since complete has been called now?     

at point should call database ask code of newly inserted question. second question, before ask found link nested transaction . in light of above link want still ask if have this

try {     var transactionoption = new transactionoptions();     transactionoption.isolationlevel = isolationlevel.readcommitted;     transactionoption.timeout = transactionmanager.maximumtimeout;      using (var outerscope = new transactionscope(transactionscopeoption.requiresnew, transactionoption)) {         try {             var transactionoption = new transactionoptions();             transactionoption.isolationlevel = isolationlevel.readcommitted;             transactionoption.timeout = transactionmanager.maximumtimeout;              using (var innerscope = new transactionscope(transactionscopeoption.requiresnew, transactionoption)) {                 //create question creates new question in database                 helpers.createquestionbankitem(ref mappedoldnewquestionitemguid, missingquestionbankitems);                 //question created                  //query database code of newly inserted question, database give me code since complete has not been called yet?                      innerscope.complete();             }         }         catch (exception ex) {         }          //query database code of newly inserted question,  database give me code since complete has been called now?              outerscope.complete();     } } catch (exception ex) {     throw; } 

if innerscope completes, querying sql server give me code of newly created question.

what happens if inner scope throws exception , gobble up, outer scope disposed off?

does calling innerscope.complete() completes inner scope?

if want recover failure in transactional context need use transaction savepoints. unfortunately managed system.transaction has no support savepoints. not that, won't able use savepoints, directly, if use transaction scopes, because transaction scope escalate distributed transactions , savepoints not work in distributed contexts.

you can use instead platform specific sqltransaction supports save() savepoints. see exception handling , nested transactions example of transaction-aware exception handling.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -