What is the default value in the machine.config for maxTimeout
(see example) if no "system.transactions" element is present on the machine.config?
<system.transactions>
<machineSettings maxTimeout="??:??:??" />
</system.transactions>
I'm asking this because the code is crashing due the following exception and it seems that it's related to the transaction exceeding a timeout, it is crashing during the SaveChanges
method and the exception that I'm receiving 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 the piece of code that is crashing:
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 the 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);
}
The value is 8 hours by default. max_execution_time, controls the timeout for SQL execution in the connection.
A lock timeout occurs when a transaction, waiting for a resource lock, waits long enough to have surpassed the wait time value specified by the locktimeout database configuration parameter. This consumes time which causes a slow down in SQL query performance.
You can place a limit on the amount of time a SQL database session is allowed to be idle before the system terminates it. You can impose timeouts on both individual users and groups.
The auto-commit transaction mode is the default transaction mode of the SQL Server.
There is not a server side time-out is MS SQL.
It is always the client that throws an exception after a set duration.
http://blogs.msdn.com/b/khen1234/archive/2005/10/20/483015.aspx
You are really wanting to look at the command time-out.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspx
The default here is 30 seconds.
Default = 10 minutes. Max = Infinity
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With