本文介绍了在SQL中,默认的最大事务超时时间是多少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果在machine.config中没有"system.transactions"元素,则 maxTimeout
的machine.config中的默认值是什么?(见示例)?
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>
我之所以这样问是因为代码由于以下异常而崩溃,并且似乎与事务超时有关,在 SaveChanges
方法期间崩溃,并且我m接收如下:
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.
这是崩溃的代码:
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
Default = 10 minutes. Max = Infinity
这篇关于在SQL中,默认的最大事务超时时间是多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!