.net - SQL中默认的最大事务超时是多少

标签 .net sql sql-server transactions timeout

如果 machine.config 上不存在“system.transactions”元素,则 machine.config 中 maxTimeout 的默认值是多少(请参阅示例)?

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

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

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 分钟。最大值 = Infinity

关于.net - SQL中默认的最大事务超时是多少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5915462/

相关文章:

c# - 如何在wpf treeview中显示所有直接和间接子成员的数量

c# - .NET 正则表达式匹配方法中一致的字符串开头 anchor 行为

sql - SQL日期时间需要读取00 :00:00. 000

sql-server - SQL Server 全文搜索使用 CONTAINS、FORMSOF、NEAR 进行多个搜索词

sql-server - 在 Azure SQL 中批量插入 Parquet 文件

c# - 如何在 HttpClient response.ReasonPhrase 中获取真正的错误消息?

带有 C# DLL 的 Python CLR 模块 - AddReference 有效,导入无效

php - 向mysql中的WHERE子句添加动态数量的变量

sql - 使用 `REPLACE`函数的Oracle UPDATE语句

mysql - 使用sql中的case语句填充三列的总和