title: Problem with Rolling back a linq2sql insert transaction in C#
body: <p>i am trying to insert the contents of a CSV file into a database table using linq2SQL.</p>
  
  <p>I want to be able to rollback the transaction if <strong>ANY</strong> of the inserts fail but when i try with this code i get the following error at - <strong>db.Transaction.Commit()</strong></p>
  
  <p><strong>System.InvalidOperationException was unhandled: This SqlTransaction has completed; it is no longer usable.</strong></p>
  
  <p>Does anyone know what i am doing wrong?</p>
  
  <pre><code>using (DataContext db = new DataContext())
  {
      db.Connection.Open();
      db.Transaction = db.Connection.BeginTransaction();
  
      try
      {
          foreach (string entry in entries)
          {
              XXX xxx = new XXX()
              {
                  P1 = "something",
                  P2 = "something"
              };
  
              db.XXXX.InsertOnSubmit(xxx);
              db.SubmitChanges();
          }
      }
      catch (Exception)
      {
          db.Transaction.Rollback();
      }
      finally
      {
          db.Connection.Close();
      }
  
      db.Transaction.Commit();
  }
  </code></pre>