TransactionScope and NServiceBus

Currently, my program makes use of NService bus and it queries the database a lot of the time. Issue is, when it gets to a certain point in the process, it always gets this error

    System.Transactions.TransactionException: The operation is not valid for the state of the         transaction.
   at System.Transactions.TransactionState.EnlistVolatile(InternalTransaction tx,         IEnlistmentNotification enlistmentNotification, EnlistmentOptions enlistmentOptions, Transaction         atomicTransaction)

Now, I’ve just been able to solve this by increasing the machine timeout in machine.config. I basically followed this post.

Now, if it’s ok to find out. Is there any other way I could’ve done this?

Based on research, I feel that the database lookup is taking way to long for the handler’s transaction scope - or something along those lines.

Now, I’ve changed the machine.config. In the link above, there’s also a comment -following the link - the comment is a method on how to change this value on the fly at run time - which I prefer.

Can I please confirm it’s ok to do this or is there a different was to solve my problems?

Also, I did this on both the servers that’s hosting the application and the SQL server - out of desperation. Should I have just done this on the application server?

Look forward to your responses.

Hi,

Technically speaking what you’re doing is correct. Message processing is wrapped in a transaction and if it takes too long the transaction times out and is rolled back. The technical solution is to increase the transaction timeout.

However, changing the default transaction timeout is probably most of the times a palliative, it’s hiding the cause of the pain. You should probably redesign your message handling process, e.g., by splitting it into multiple messages each one taking shorter time.
On the other hand if you’re issueing one single query that times out it’s probably worth looking at the query itself and the database server to understand if there are improvements that can be applied there.

Cheers,
.m

Thanks very much for your response.

Any chance you could please point me to any documentation that shows this kind of message handling process. That involves using multiple messages.

Thanks in advance.

Can you describe what you’re doing during message processing, and what is the business scenario you’re trying to model?

.m