Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Transaction Timeout

I used to set Transaction timeouts by using TransactionOptions.Timeout, but have decided for ease of maintenance to use the config approach:

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

Of course, after putting this in, I wanted to test it was working, so reduced the timeout to 5 seconds, then ran a test that lasted longer than this - but the transaction does not appear to abort! If I adjust the test to set TransactionOptions.Timeout to 5 seconds, the test works as expected

After Investigating I think the problem appears to relate to TransactionOptions.Timeout, even though I'm no longer using it.

I still need to use TransactionOptions so I can set IsolationLevel, but I no longer set the Timeout value, if I look at this object after I create it, the timeout value is 00:00:00, which equates to infinity. Does this mean my value set in the config file is being ignored?

To summarise:

  • Is it impossible to mix the config setting, and use of TransactionOptions
  • If not, is there any way to extract the config setting at runtime, and use this to set the Timeout property
  • [Edit] OR Set the default isolation-level without using TransactionOptions
like image 477
MattH Avatar asked Aug 28 '09 16:08

MattH


People also ask

What is transaction timeout?

The transaction timeout is used to define the duration of a transaction, which may involve several service requests. The timeout value is defined when the transaction is started (with tpbegin(3c)).

What is maximum transaction timeout?

The "Maximum transaction timeout" the maximum time allowed for the transaction that are IMPORTED (i.e., transaction context imported from other server) to this server and any other transaction running on this server.

What happens after a transaction times out?

The transaction timeout functionality monitors the time elapsed since the transaction was started, and rolls back the transaction when the specified time has lapsed. The monitoring time is from the completion of transaction startup until the start of transaction conclusion.


1 Answers

You can get the (validated) default timeout from the configuration using TransactionManager.DefaultTimeout.

TransactionOptions is a struct that encapsulates timeout and isolation level. When initializing a struct using the default constructor, it will always initialize the struct members to their default values:

TransactionOptions transactionOptions = new TransactionOptions(); transactionOptions.Timeout == default(TimeSpan); // TimeSpan.Zero transactionOptions.IsolationLevel == default(IsolationLevel); // IsolationLevel.Serializable 

If you want to specify an IsolationLevel and use the default timeout:

new TransactionOptions() {     IsolationLevel = IsolationLevel.Serializable, // Use whatever level you require     Timeout = TransactionManager.DefaultTimeout }; 
like image 126
Ronald Avatar answered Oct 04 '22 06:10

Ronald