16 May 2021

Error - The transaction associated with the current connection has completed but has not been disposed

In .NET, you may come across the below error when you use TransactionScope

Error - The transaction associated with the current connection has completed but has not been disposed

The root cause is transaction Time Out by default it is 10 Minutes. Two possible solutions are 1. Provide explicit time out when defining TransactionScope like this.

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new System.TimeSpan([Hours], [Minutes greater than 10], [Seconds]))){ // Your code }
Some times this won't work. Another possible solution (Courtesy : https://stackoverflow.com/a/21274884/341117) is tweaking
C:\Windows\Microsoft.NET\Framework\[Version]\Config\machine.config

Note : While doing this, take absolute care. Take a back up and then edit. Wrongly editing this will stop your Visual Studio, SQL Server Management Studio and whichever applications are dependent on .NET Framework. Add the below node in that file at the end of the file before end configuration node.

 Make sure that you add at the end. If you add it in the beginning, all applications depend on .NET Framework will stop working.

 

No comments:

Post a Comment