Error: Time-out interval must be less than 2^32-2. Parameter name: dueTm
Asked Answered
I

3

1

I have a one-to-many relationship within my class model.

Example: A single role can have many permissions attached to it. so have two table one from the role and one for the permissions for each role.

Now i have a role class which in turn has a permission list as a member of that class. When i need to do an update, i instantiate a transactionscope object, and do an update for the role. After that is done and with the transactionscope still open, i open another transactionscope for each permission in the list and close it immediately after the update has been done.

The update for the role works just fine

But, now the problem is that when it tries to instantiate a transactionscope for the first permission on the list it trows an error saying:

Error: Time-out interval must be less than 2^32-2. Parameter name: dueTm
Indestructible answered 26/12, 2009 at 18:4 Comment(1)
I believe the question is about .NET Framework Transactions: msdn.microsoft.com/en-us/library/… Possibly in relation to ADO.NET and/or SQL Server 2008Vocalize
I
3

Ok, i found a solution.

Scenario: I have two base classes for my Business Layer, BaseBLL and BaseListBLL. Each of these classes provided a method that calls an astract method that must be implemented in you concrete class. These classes started a TransactionScope before handing off to the abstract class to perform tasks like update or insert.

Note: After the BaseListBLL starts off a TransactionScope it calls the method in the BaseBLL that also starts it's own transaction. This is because, we'll be inserting or updating a list of classes derived from the BaseBLL which all together are contained in a class derived from BaseListBLL.

Now for example if we are to update a role in the roles table only one transaction would be started. But now the complexity comes when we have a role object having another class that derives directly from the BaseListBLL.

A transaction would be started for the list first and another for each BaseBLL object in the list to do all the insert or update.

So now, after the first insert, the error:

Error: Time-out interval must be less than 2^32-2. Parameter name: dueTm

is thrown.

What i did was

For the list class, i set the TranscationScope object this way:

TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress)

and for the other class

TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, TimeSpan.MaxValue)

The conclusion i have derived is that the error is being thrown because i was using the same transaction created by the BaseBLL derived class from the list. I had to suppress the ambient transaction when it was time to do an update of the list of items.

I hope this helps someone else.

Indestructible answered 27/12, 2009 at 12:44 Comment(0)
C
1

We had a similar issue and the answer to this is simple and is found in this thread.

What's happening is that the outer TransactionScope and the inner TransactionScope have a Timeout mismatch. The inner TransactionScope is trying to set itself as something greater than the outer TransactionScope.

How does this happen? The answer is that we were setting the Timeout to be equal to TimeSpan.MaxValue...BUT...the limit for this is actually TransactionManager.MaximumTimeout. So when the inner TransactionScope sets the timeout it blows up because it is a value greater than the outer TransactionScope.

This caused problems when nesting transactions:

public static TransactionScope CreateTransactionScope()
        {
            var transactionOptions = new TransactionOptions
            {
                IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted,
                Timeout = TimeSpan.MaxValue
            };

            return new TransactionScope(TransactionScopeOption.Required, transactionOptions);
        }

This works fine when nesting transactions:

public static TransactionScope CreateTransactionScope()
        {
            var transactionOptions = new TransactionOptions
            {
                IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted,
                Timeout = TransactionManager.MaximumTimeout
            };

            return new TransactionScope(TransactionScopeOption.Required, transactionOptions);
        }

The person who answered claims this is a known bug. In my opinion the fix would simply be to 'fail fast' and throw an exception if the Timeout is set to a value greater than TransactionManager.MaximumTimeout instead of throwing an exception if the inner TransactionScope tries to set a value greater than the outer TransactionScope.

Coverley answered 21/2, 2014 at 13:6 Comment(0)
S
0

The source code of the class System.Transactions.TransactionScope shows that it will create a System.Threading.Timer instance in some situations. The timer requires that dueTime.TotalMilliseconds should not be greater than 0xfffffffeL, but the value passed to dueTime is TimeSpan.MaxValue (0x7fffffffffffffffL in ticks, namely, 0x346DC5D638865 in milliseconds). That's why the exception is thrown.

So I think the better solution is to give the TransactionScope a smaller timeout.

Substantive answered 27/7, 2012 at 7:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.