title: Can I mix SqlConnection.BeginTransaction and TransactionScope?
body: <p>This is related to the <a href="https://stackoverflow.com/questions/772729/nested-database-transactions-in-c">Nested Database transactions in C#</a>.</p>
  
  <p>The objects in collection I want to take in transaction implement their own transactions using SqlConnection.BeginTransaction method.</p>
  
  <p>After reading this <a href="http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic63806.aspx" rel="nofollow noreferrer">post</a> I am not sure if I can mix those too or not.
  I am using SQL Server 2005 and each object uses connection details from static configuration class.</p>
  
  <p>Does anybody have experience with this ?</p>
  
  <p>Here is the sample code:</p>
  
  <pre><code>using(TransactionScope scope = new TransactionScope())
  {
    for (int i=0; i&lt;=1000....) 
    {
      SqlConnection con = new SqlConnection()
      SqlCommand cmd = new SqlCommand("delete from ...", con); 
  
      try {
         con.Open(); 
         DbTransaction t = con.BeginTransaction();
         cmd.ExecuteNonQuery(); 
         ...
         cmd.CommandText = .... ;
         cmd.ExecuteNonQuery(); 
         t.Commit  ...
      } 
      catch {
         t.Rollback ...
      }
      con.Close()
    }
  }
  </code></pre>
  
  <p>Thx</p>