What is the default value in machine.config for maxTimeout (see example) if there is no "system.transactions" element in the machine.config file?
<system.transactions> <machineSettings maxTimeout="??:??:??" /> </system.transactions>
I ask this because the code crashes due to the following exception and it seems to be associated with a transaction that exceeds the timeout, it crashes during the SaveChanges method, and the exception that I get is the following
The transaction associated with the current connection has completed but has not been disposed. The transaction must be disposed before the connection can be used to execute SQL statements.
This is a piece of code that crashes:
using (TransactionScope transaction = TransactionHelper.CreateTransactionScope()) { using (EFContext efDBContext = new EFContext()) { try { efDBContext.Connection.Open(); foreach (MyEntity currentEntity in myEntities) { //Insertion } transaction.Complete(); } catch (Exception ex) { //Inspect current entity //Get Total Time of the run //Number of entities processed } finally { if (esfDBContext.Connection.State == ConnectionState.Open) esfDBContext.Connection.Close(); } } }
This is how I create a TransactionScope :
public static TransactionScope CreateTransactionScope(TransactionScopeOption option = TransactionScopeOption.Required, IsolationLevel isolationLevel = IsolationLevel.ReadCommitted) { var transactionOptions = new TransactionOptions() { Timeout = TimeSpan.MaxValue, IsolationLevel = isolationLevel }; return new TransactionScope(option, transactionOptions); }
source share