开发者

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();
        }开发者_如何学JAVA
        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);
}


Default = 10 minutes. Max = Infinity


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜