Transaction scope timeout on 10 minutes

Patrick picture Patrick · Aug 21, 2012 · Viewed 68.4k times · Source

I have a long running TransactionScope in C#. I told the scope that it should have a long timespan, but still I get a timeout. What could cause this?

TransactionOptions transactionOptions = new TransactionOptions();
transactionOptions.IsolationLevel = IsolationLevel.ReadCommitted;
transactionOptions.Timeout = TimeSpan.MaxValue;
using (var ts = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
{ 
    DoLongCode();
}

Answer

Eric Schneider picture Eric Schneider · Oct 17, 2012

To further clarify:

Transaction Scope uses the Machine config setting as the maximum timeout. The default machine timeout is 10 minutes.

Setting the machine config to 2 hours:

      <system.transactions>
        <machineSettings maxTimeout="02:00:00"/>
      </system.transactions> 

The app.config or web.config can be used reduced to the timeout but can not be used to exceed the machine config timeout.

Setting the app config to 1 hour:

<system.transactions>
     <defaultSettings timeout="01:00:00" />
</system.transactions>

Also we did NOT receive any exceptions when the limit was reached, also no trace or event log records.

Also the TransactionScope object has constructor overloads which allow you to specify a timeout, but I'm not sure how that is handled.