title: Nested transaction scope .net
body: <p>I'm using SQL Server 2008 R2 and trying to use transactions.</p>
  
  <p>First a question about transactions in .net and SQL Server. If I have something like this</p>
  
  <pre><code>try {
      var transactionOption = new TransactionOptions();
      transactionOption.IsolationLevel = IsolationLevel.ReadCommitted;
      transactionOption.Timeout = TransactionManager.MaximumTimeout;
  
      using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, transactionOption)) {
          //create question this creates a new question in the database
          Helpers.CreateQuestionBankItem(ref mappedOldNewQuestionItemGuid, missingQuestionBankItems);
          //question created
  
          //query database for the code of the newly inserted question, will the database give me the code since Complete has not been called as yet?    
  
  
  
          scope.Complete();
      }
  }
  catch (Exception ex) {
      throw;
  }
  
  //query database for the code of the newly inserted question,  will the database give me the code since Complete has been called as now?    
  </code></pre>
  
  <p>At which point should I call the database to ask for the code of the newly inserted question. Now my second question, before I ask I found this link <a href="http://www.sqlskills.com/blogs/paul/a-sql-server-dba-myth-a-day-2630-nested-transactions-are-real/" rel="nofollow">Nested Transaction</a> . In the light of the above link I want to still ask that if I have something like this</p>
  
  <pre><code>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 this creates a new question in the database
                  Helpers.CreateQuestionBankItem(ref mappedOldNewQuestionItemGuid, missingQuestionBankItems);
                  //question created
  
                  //query database for the code of the newly inserted question, will the database give me the code since Complete has not been called as yet?    
  
                  innerscope.Complete();
              }
          }
          catch (Exception ex) {
          }
  
          //query database for the code of the newly inserted question,  will the database give me the code since Complete has been called as now?    
  
          outerscope.Complete();
      }
  }
  catch (Exception ex) {
      throw;
  }
  </code></pre>
  
  <p>If my innerscope completes, will querying SQL Server give me the code of the newly created question. </p>
  
  <p>What happens if the inner scope throws an exception and I gobble it up, will the outer scope also be disposed off?</p>
  
  <p>Does calling innerscope.Complete() completes that inner scope?</p>