在 SQL 中什么是默认的最大事务超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5915462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 10:26:40  来源:igfitidea点击:

In SQL What is the default max transaction timeout

.netsqlsql-servertransactionstimeout

提问by Bongo Sharp

What is the default value in the machine.config for maxTimeout(see example) if no "system.transactions" element is present on the machine.config?

maxTimeout如果machine.config 上没有“system.transactions”元素,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 SaveChangesmethod and the exception that I'm receiving is the following:

我问这个是因为代码由于以下异常而崩溃,并且似乎与超过超时的事务有关,它在SaveChanges方法期间崩溃,我收到的异常如下:

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:

这就是我创建的方式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);
}

回答by gbn

Default = 10 minutes. Max = Infinity

默认值 = 10 分钟。最大值 =无穷大

回答by iain

There is not a server side time-out is MS SQL.

没有服务器端超时是 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

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

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspx

The default here is 30 seconds.

此处的默认值为 30 秒。