C# 事务超时错误
在我的C#应用程序中,我必须执行3个任务,我将所有任务都放在一个事务范围内,并将事务超时设置为30分钟C# 事务超时错误,c#,transactions,ado.net,C#,Transactions,Ado.net,在我的C#应用程序中,我必须执行3个任务,我将所有任务都放在一个事务范围内,并将事务超时设置为30分钟 using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, new TimeSpan(0, 30, 0))) { //1. Create an entry in database table
using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew,
new TimeSpan(0, 30, 0)))
{
//1. Create an entry in database table
//2. call some external perl script which push data
to some table
//3. update the table (step 1) with number of records generated (step 2)
scope.Complete();
}
通常步骤2需要10分钟的时间来执行,步骤3需要5分钟的时间(步骤1非常快)
我也为步骤3设置了命令超时
sqlCom.CommandTimeout = 1800;
事务的所有3个任务都在最多15-20分钟内完成,但我仍然收到超时错误
System.Transactions.TransactionAbortedException: The transaction has
aborted. ---> System.TimeoutException: Transaction Timeout
--- End of inner exception stack trace ---
at
System.Transactions.TransactionStateAborted.BeginCommit(InternalTransaction
tx, Boolean asyncCommit, AsyncCallback asyncCallback, Object asyncState)
at System.Transactions.CommittableTransaction.Commit()
at System.Transactions.TransactionScope.InternalDispose()
at System.Transactions.TransactionScope.Dispose()
注意-当第2步和第3步花费更少的时间(平均2-3分钟)时,我没有收到任何超时错误
请建议我是否可以设置其他设置?您需要在machine.config中修改事务超时值,请检查并重试。默认值为10分钟,这将优先于所有其他设置,同时确保高命令超时,因为这也将中止事务。您需要在machine.config中修改事务超时值,请选中并单击。默认值为10分钟,这将优先于所有其他设置,还将确保高命令超时,因为这也将中止事务