Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 事务超时错误_C#_Transactions_Ado.net - Fatal编程技术网

C# 事务超时错误

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

在我的C#应用程序中,我必须执行3个任务,我将所有任务都放在一个事务范围内,并将事务超时设置为30分钟

 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分钟,这将优先于所有其他设置,还将确保高命令超时,因为这也将中止事务