在SQL中,默认的最大事务超时是多少?



机器的默认值是多少?如果没有"system. config",则为maxTimeout配置(参见示例)。"事务"元素存在于machine.config?

<system.transactions>
   <machineSettings maxTimeout="??:??:??" />
</system.transactions>

我问这个问题是因为代码由于以下异常而崩溃,似乎它与超过超时的事务有关,它在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.

即将崩溃的代码:

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();
        }
    }
}

这是我如何创建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);
}

默认值= 10分钟。Max = Infinity

没有服务器端超时是MS SQL。

总是客户端在设定的持续时间后抛出异常。

http://blogs.msdn.com/b/khen1234/archive/2005/10/20/483015.aspx

你真的想看看命令超时。

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

默认为30秒

相关内容

  • 没有找到相关文章

最新更新