Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In SQL What is the default max transaction timeout

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);
}
like image 852
Bongo Sharp Avatar asked May 06 '11 18:05

Bongo Sharp


People also ask

What is the max SQL timeout?

The value is 8 hours by default. max_execution_time, controls the timeout for SQL execution in the connection.

What is a SQL lock timeout?

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.

What is session timeout in SQL Server?

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.

What is default transaction mode in SQL Server?

The auto-commit transaction mode is the default transaction mode of the SQL Server.


2 Answers

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.

like image 65
iain Avatar answered Sep 22 '22 05:09

iain


Default = 10 minutes. Max = Infinity

like image 29
gbn Avatar answered Sep 21 '22 05:09

gbn