title: How does a SqlConnection knows that it is executed in a TransactionScope
body: <p>For a project I'm writing a bunch of queries, which are in it's own separately, but they need to be executed in a transaction. </p>
  
  <p>I'm using a <a href="http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope%28v=vs.110%29.aspx" rel="nofollow"><code>TransactionScope</code></a></p>
  
  <p>Consider the following code:</p>
  
  <pre><code>// connection = new SqlConnection(...); 
  // connection.Open();
  
  using(var transactionScope = new TransactionScope())
  {
      // execute first query on connection
      using(var sqlCommand = new SqlCommand("DELETE THIS", connection))
      {
          // sqlCommand.Parameters....
          sqlCommand.ExecuteNonQuery();
      }
  
      // second query
      using(var sqlCommand = new SqlCommand("INSERT THAT", connection))
      {
          // sqlCommand.Parameters....
          sqlCommand.ExecuteNonQuery();
      }
  
      transactionScope.Complete();
  }
  </code></pre>
  
  <p>Now how does the <code>sqlCommand</code> know that somewhere in previous code I have a <code>transactionScope</code>? </p>