Several sessions in a TransactionScope

I wanted to test concurrency control using optimistic locking in NHibernate and needed a unit test that generated a StaleObjectStateException. To do this I simulated two simultaneous client by two database sessions in the unit test. Both sessions read the same entity, thereafter they modified the content and saved the changes. The last save will cause a StaleObjectStateException, since it violates the ACID rules of the transaction. I run all my tests in a transaction scope and to be able to run several sessions in one transaction scope I had to change the settings for MSDTC on the database server.

1) Open the control panel.

2) Open “Administrative Tools->Component Services”.

3) In the left tree view, navigate to “Component Services->Computers->My Computer”.

4) Right click on “My Computer” and select properties.

5) Select “MSDTC” tab and click on “Security Configuration”.

6) Check “Network DTC Access”, “Allow Remote Client” and “Allow Inbound/Outbound”.

7) Restart service.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.