No Free Time

Because my therapist says I need to let things out

How to fix TransactionScope “already been implicitly or explicitly committed or aborted” error

Posted by andrewmyhre on February 14, 2008

I got this error while running unit tests my local machine for a codebase which has been stable for a few months. Up til now the unit tests have been running without problems on our build server, but I’m adding to the codebase so I’m running them locally.

The error occurs when we execute any kind of SQL within an open TransactionScope, and then try to commit the transaction. I found my unit tests were failing waaaay more than they should be, and were taking waaay longer than they should to run (some were taking 8 seconds or more to run a simple insert or update test). The error log was giving me the following:

Message: The transaction has already been implicitly or explicitly committed or aborted.

Type: System.Transactions.TransactionException
Source: System.Transactions
TargetSite: Void ProxyException(System.Runtime.InteropServices.COMException)
HelpLink: null
Stack: at System.Transactions.Oletx.OletxTransactionManager.ProxyException(COMException comException)
at System.Transactions.TransactionInterop.GetExportCookie(Transaction transaction, Byte[] whereabouts)
at System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)
at System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction)
at System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()

A quick search turned up a forum thread which solved the problem for me – Windows Firewall was messing with the transactions. Turning it off made my unit tests complete quickly and with most tests passing again.

In case that doesn’t help in your situation, here are a number of threads to read for other explanations/solutions:

http://forums.asp.net/t/1017415.aspx
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=167289&MovedStatus=MovedAlreadyApproved&SiteID=1

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=124293&SiteId=1

One Response to “How to fix TransactionScope “already been implicitly or explicitly committed or aborted” error”

  1. امین said

    I am very happy to find your weblog because I could solve my problem in transaction with your post.
    Good luck.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>