views:

178

answers:

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
A: 

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.

Colour Blend