This is the simplified code of the test case I was working on:
using (var scope = new
TransactionScope(TransactionScopeOption.RequiresNew, new
TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
{
// enforce the usage of dtc
Transaction.Current.EnlistDurable(Guid.NewGuid(), new
MyDummyEnlistmentNotification(), EnlistmentOptions.None);
using (var outerSession = firstSessionFactory.OpenSession())
using (var innerSession = secondSessionFactory.OpenSession())
using (var outerTransaction = outerSession.BeginTransaction())
using (var innerTransaction = innerSession.BeginTransaction())
{
try
{
// all other code left out
innerTransaction.Commit();
outerTransaction.Commit();
scope.Complete();
}
catch (Exception)
{
// when Transaction.Current was aborted you should not call
Rolback() anymore as this call will fail
if (Transaction.Current.TransactionInformation.Status !=
TransactionStatus.Aborted)
{
innerTransaction.Rollback();
outerTransaction.Rollback();
}
}
}
}
Both sessions connect to a different database server. Once the
transaction is aborted due to an error on one of the servers,
NHibernate will still try to rollback the transactions on the server
when Dispose() is called on the TransactionScope. This results in the
exception "The ROLLBACK TRANSACTION request has no corresponding BEGIN
TRANSACTION.".
This exception is thrown inside that Dispose() method and does not
propagate to my code. But it seems that not everything is cleaned up
correctly as subsequent requests sometimes fail with the following
exception:
NHibernate.TransactionException: Begin failed with SQL exception ----
> System.Data.SqlClient.SqlException: New request is not allowed to
start because it should come with valid transaction descriptor.
Any thoughts on this problem?
> >
nhusers+u...@googlegroups.com<
nhusers%2Bunsu...@googlegroups.com>
> > .