1

In my C# application I have to perform 3 task and I am putting all within a transaction scope and I am setting transaction time out 30 minutes.

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

Usually step 2 is taking 10 minutes time to execute and step 3 is taking 5 minutes time (step 1 is real quick).

I do also set command time out for step 3 is,

sqlCom.CommandTimeout = 1800;

All 3 tasks for the transaction is completed in max 15-20, but still I am getting timeout error,

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

Note - When steps 2 and 3 take less time (2-3 minutes average), then I am not getting any timeout error.

Please suggest if I can set something else?

user584018
  • 10,186
  • 15
  • 74
  • 160
  • 1
    You need modify the Transaction timeout value in machine.config, check [this](http://stackoverflow.com/questions/1348191/default-transaction-timeout) and [this](http://support.objectivity.com/sites/default/files/docs/objy/R11_0_0/html/csharp/html/d6957adb-fa07-45d5-8433-a9ab602afdec.htm). Default is 10 minutes, which will prevail over all other settings, also ensure high Command Timeout, as that will too abort the transaction – Mrinal Kamboj Apr 19 '17 at 07:16

0 Answers0