-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Two sessions in one TransactionScope failing
PostPosted: Thu Jul 16, 2009 11:01 pm 
I've been struggling to get multiple sessions to work within the same transaction. I've created an architecture based on this article http://codebetter.com/blogs/karlseguin/ ... bases.aspx that has two SessionFactories (for two DBs) and two sessions.

I have written a number of unit tests that work (read from two DBs, edit one and then the other, etc), but as soon as I try to wrap any of them in a TransactionScope it fails. As soon as I try to access the second session, I get one of a number of issues.

-If I look at the session in the debugger, it seems corrupt saying "Function Evaluation Timed Out"
-If I let it time out, I get "System.Transactions.TransactionManagerCommunicationException: Communication with the underlying transaction manager has failed" for 2.0.1 or "System.Transactions.TransactionException: The operation is not valid for the state of the transaction for NHibernate 2.1.

It seems like looking at the first session, throws the second session into a weird state. I've tried re-creating the session, disconnecting, etc. but nothing seems to work.

Is there no way to get two sessions to work within the same transaction? I really want to make sure that the data stays consistent across the two DBs.


Top
  
 
 Post subject: Re: Two sessions in one TransactionScope failing
PostPosted: Thu Jan 21, 2010 6:16 am 
Newbie

Joined: Wed Aug 06, 2008 2:43 am
Posts: 2
Are you sure that distributed transactions are enabled?
test it by making one system.transaction with the two connections in it without using nhibernate...

To enable DTC do the following procedure:
First verify the "Distribute Transaction Coordinator" Service is
running on both database server computer and client computers
1. Go to "Administrative Tools > Services".
2. Turn on the "Distribute Transaction Coordinator" Service if it is not running.

If it is running and client application is not on the same computer as
the database server, on the computer running database server:
1. Go to "Administrative Tools > Component Services".
2. On the left navigation tree, go to "Component Services > Computers > My Computer" (you may need to double click and wait as some nodes need time to expand)
3. Right click on "My Computer", select "Properties".
4. Select the "MSDTC" tab.
5. Click "Security Configuration".
6. Make sure you check "Network DTC Access", "Allow Remote Client", "Allow Inbound/Outbound", "Enable TIP" (Some option may not be necessary, have a try to get your configuration).
7. The service will restart.
8. BUT YOU MAY NEED TO REBOOT YOUR SERVER IF IT STILL DOESN'T WORK.

On your client computer use the same above procedure to open the "Security Configuration" setting, make sure you check "Network DTC Access", "Allow Inbound/Outbound" option, and restart service and computer if necessary.

On you SQL server service manager, click "Service" dropdown, select "Distribute Transaction Coordinator", it should be also running on your server computer.


Top
 Profile  
 
 Post subject: Re: Two sessions in one TransactionScope failing
PostPosted: Thu Jan 21, 2010 11:00 am 
Thanks for the response. I did eventually figure out the solution, but it was so long ago I forgot exactly what it was. It wasn't a configuration issue, such as DTC not running. Looking at the code, I think it was something as silly as swapping the order that the config.BuildSessionFactory() was run and it magically worked. It never made any sense but has continued to work for the past 6+ months.


Top
  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.