title: Does SqlBulkCopy automatically start a transaction?
body: <p>I am inserting data via <code>SqlBulkCopy</code> like so:</p>
  
  <pre><code>public void testBulkInsert(string connection, string table, DataTable dt)
  {
      using (SqlConnection con = new SqlConnection(connection))
      {
          con.Open();
  
          using (SqlBulkCopy bulkCopy = new SqlBulkCopy(con))
          {
              bulkCopy.DestinationTableName = table;
              bulkCopy.WriteToServer(dt);
          }
      }
  }
  </code></pre>
  
  <p>Will this automatically be wrapped in a SQL transaction so that if something goes wrong half way through the DB will be left in the same state as it was before the bulk insert began? Or will half the data be inserted?</p>
  
  <p>i.e. is it necessary for me to explicitly call <code>con.BeginTransaction</code></p>
  
  <p>Or if I call <code>SqlBulkCopy</code>'s constructor that takes a string, is that a better way of getting it to occur in a transaction?</p>
  
  <pre><code>public void testBulkInsert(string connection, string table, DataTable dt)
  {
      using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection))
      {
          bulkCopy.DestinationTableName = table;
          bulkCopy.WriteToServer(dt);
      }
  }
  </code></pre>
  
  <p>I find the <a href="http://msdn.microsoft.com/en-us/library/tchktcdk(v=vs.110).aspx" rel="noreferrer">docs</a> a bit unclear on this matter as they initially state that</p>
  
  <blockquote>
    <p>By default, a bulk copy operation is performed as an isolated
    operation. The bulk copy operation occurs in a non-transacted way,
    with no opportunity for rolling it back</p>
  </blockquote>
  
  <p>but then later state</p>
  
  <blockquote>
    <p>By default, a bulk copy operation is its own transaction. When you
    want to perform a dedicated bulk copy operation, create a new instance
    of SqlBulkCopy with a connection string, or use an existing
    SqlConnection object without an active transaction. In each scenario,
    the bulk copy operation creates, and then commits or rolls back the
    transaction.</p>
  </blockquote>
  
  <p>So is it necessary to do:</p>
  
  <pre><code>public void testBulkInsert(string connection, string table, DataTable dt)
  {
      using (SqlConnection con = new SqlConnection(connection))
      {
          con.Open();
          using (SqlTransaction tr = con.BeginTransaction(IsolationLevel.Serializable))
          {
              using (SqlBulkCopy bulkCopy = new SqlBulkCopy(con, SqlBulkCopyOptions.Default, tr))
              {
                  bulkCopy.DestinationTableName = table;
                  bulkCopy.WriteToServer(dt);
              }
              tr.Commit();
          }
      }
  }
  </code></pre>