Manage System.Transaction timeout

When using System.Transaction in .net framework; you may came across a timeout problem where you code needs longer time to run than the default timeout duration for System.Transaction.. this is because the System.Transaction will be aborted after few seconds which will rollback your changes.. to make the timeout longer than the default timeout duration, you need to adjust your code to do this, there is no configuration on IIS/appconfig level to accomplish that. the following code sample showing how to accomplish this from code perspective

TimeSpan timeoutDuration = TimeSpan.FromSeconds(180);
using(TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, timeoutDuration))
{


Scope.Complete();
}

The timeout default value is 60 seconds; if you want to have an infinite timeout; just set it to be 0.

You need also to change values on machine.config in case you made the timeout value more than 10 minutes. Because the machine.config has a configurable value to limit TransactionManager’s timeout to be 10 minutes at max.

TransactionManager is setting on top of the transaction object; thus it has the upper hand on it if you exceed the 10 minutes limit. The problem with TransactionManager is you can’t change the timeout default value programmatically and you need to update the machine.config to accomplish this. To do so change the following tag value on machine.config

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