Skip to content

Commit 183dfe0

Browse files
committed
Merge branch 'flcdrg-NH-3454'
closes #206
2 parents 06cdc28 + 7b60229 commit 183dfe0

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

src/NHibernate/Transaction/AdoNetWithDistributedTransactionFactory.cs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,31 +36,38 @@ public void EnlistInDistributedTransactionIfNeeded(ISessionImplementor session)
3636
logger.DebugFormat("enlisted into DTC transaction: {0}",
3737
transactionContext.AmbientTransation.IsolationLevel);
3838
session.AfterTransactionBegin(null);
39-
transactionContext.AmbientTransation.TransactionCompleted +=
40-
delegate(object sender, TransactionEventArgs e)
39+
40+
TransactionCompletedEventHandler handler = null;
41+
42+
handler = delegate(object sender, TransactionEventArgs e)
43+
{
44+
using (new SessionIdLoggingContext(session.SessionId))
4145
{
42-
using (new SessionIdLoggingContext(session.SessionId))
46+
((DistributedTransactionContext) session.TransactionContext).IsInActiveTransaction = false;
47+
48+
bool wasSuccessful = false;
49+
try
4350
{
44-
((DistributedTransactionContext)session.TransactionContext).IsInActiveTransaction = false;
45-
46-
bool wasSuccessful = false;
47-
try
48-
{
49-
wasSuccessful = e.Transaction.TransactionInformation.Status
50-
== TransactionStatus.Committed;
51-
}
52-
catch (ObjectDisposedException ode)
53-
{
54-
logger.Warn("Completed transaction was disposed, assuming transaction rollback", ode);
55-
}
56-
session.AfterTransactionCompletion(wasSuccessful, null);
57-
if (transactionContext.ShouldCloseSessionOnDistributedTransactionCompleted)
58-
{
59-
session.CloseSessionFromDistributedTransaction();
60-
}
61-
session.TransactionContext = null;
51+
wasSuccessful = e.Transaction.TransactionInformation.Status
52+
== TransactionStatus.Committed;
53+
}
54+
catch (ObjectDisposedException ode)
55+
{
56+
logger.Warn("Completed transaction was disposed, assuming transaction rollback", ode);
57+
}
58+
session.AfterTransactionCompletion(wasSuccessful, null);
59+
if (transactionContext.ShouldCloseSessionOnDistributedTransactionCompleted)
60+
{
61+
session.CloseSessionFromDistributedTransaction();
6262
}
63-
};
63+
session.TransactionContext = null;
64+
}
65+
66+
e.Transaction.TransactionCompleted -= handler;
67+
};
68+
69+
transactionContext.AmbientTransation.TransactionCompleted += handler;
70+
6471
transactionContext.AmbientTransation.EnlistVolatile(transactionContext,
6572
EnlistmentOptions.EnlistDuringPrepareRequired);
6673
}

0 commit comments

Comments
 (0)