title: SqlTransaction has completed
body: <p>I have an application which potentially does thousands of inserts to a SQL Server 2005 database. If an insert fails for any reason (foreign key constraint, field length, etc.) the application is designed to log the insert error and continue.</p>
  
  <p>Each insert is independent of the others so transactions aren't needed for database integrity. However, we do wish to use them for the performance gain. When I use the transactions we'll get the following error on about 1 out of every 100 commits.</p>
  
  <pre><code>This SqlTransaction has completed; it is no longer usable.
     at System.Data.SqlClient.SqlTransaction.ZombieCheck()
     at System.Data.SqlClient.SqlTransaction.Commit()
  </code></pre>
  
  <p>To try to track down the cause I put trace statements at every transaction operation so I could ensure the transaction wasn't being closed before calling commit. I've confirmed that my app wan't closing the transaction.
  I then ran the app again using the exact same input data and it succeeds.</p>
  
  <p>If I turn the logging off it fails again. Turn it back on and it succeeds. This on/off toggle is done via the app.config without the need to recompile.</p>
  
  <p>Obviously the act of logging changes the timing and causes it to work. This would indicate a threading issue. However, my app isn't multi-threaded.</p>
  
  <p>I've seen one MS KB entry indicating a bug with .Net 2.0 framework could cause similar issues (<a href="http://support.microsoft.com/kb/912732" rel="nofollow noreferrer">http://support.microsoft.com/kb/912732</a>). However, the fix they provided doesn't solve this issue.</p>