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:
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)).
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.
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.
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 };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With