I'm having a pretty serious problem with System.Transactions and NH. I am
using the trunk, and I can package up a complete test case if no one knows a
solution off-hand.
Everything works great when I open a session within a TransactionScope, unless
the transaction is promoted due to something else enlisting in the scope. I
have the following test case, with a very simple mapped class. As you can see,
my process is:
1. Begin a TransactionScope
2. Receive and send a MSMQ message
3. Open a session
4. Do some db work within the session
5. Force a rollback by throwing an exception
6. Thread.Sleep for 60 seconds.
After about 20 seconds I see the following error occur on another thread:
System.InvalidOperationException: Disconnect cannot be called while a
transaction is in progress.
at NHibernate.AdoNet.ConnectionManager.Disconnect()
in ConnectionManager.cs: line
158<about:file%3A%2F%2Fd%3AMiscellaneous%20Files%2Ff%3AConnectionManager.cs%3Fline%3D158%26column%3D1>
...
I have tried both Postgresql with the latest Npgsql driver and MS SQL Server
2005. If I take out the MSMQ stuff so that the transaction is NOT promoted,
everything is fine and dandy. Any ideas? Am I doing something wrong here?
[Test]
public void QuickTransactionScopeTest()
{
var sessionFactory = GetSessionFactory();
using (var tx = new
TransactionScope(TransactionScopeOption.RequiresNew))
{
var q = new
MessageQueue(@".\Private$\somequeue");
var msg = q.Receive();
q.Send(msg,
MessageQueueTransactionType.Automatic);
using (var sess = sessionFactory.OpenSession())
{
try
{
var dummy =
sess.Get<TestModel>(1);
dummy.TestProperty += "changed!";
throw new
Exception("Roll em back, boys.");
tx.Complete();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
Thread.Sleep(60000);
Console.WriteLine("Done!");
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---