Skip to content

Commit 27454a0

Browse files
NH-2176 - handling null enlistment (and forgotten update of stored ambient transaction).
1 parent 42af102 commit 27454a0

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/NHibernate/AdoNet/ConnectionManager.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ private void CloseConnection()
155155
{
156156
Factory.ConnectionProvider.CloseConnection(_connection);
157157
_connection = null;
158+
_connectionAmbientTransaction = null;
158159
}
159160

160161
public DbConnection GetConnection()
@@ -374,10 +375,17 @@ public void EnlistIfRequired()
374375
var tran = System.Transactions.Transaction.Current;
375376
if (tran == _connectionAmbientTransaction)
376377
return;
378+
379+
if (tran == null && !Factory.Dialect.RequiresNullEnlistment)
380+
{
381+
_connectionAmbientTransaction = null;
382+
return;
383+
}
377384
// Will fail if the connection is already enlisted in another not yet completed transaction.
378385
// Probable case: nested transaction scope. Supporting this could be done by releasing the
379386
// connection instead of enlisting.
380387
_session.Connection.EnlistTransaction(tran);
388+
_connectionAmbientTransaction = tran;
381389
}
382390

383391
private bool RequireConnectionSwapInDtc

src/NHibernate/Dialect/Dialect.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,12 @@ public IList<SqlString> GetTokens()
14101410
/// </summary>
14111411
public virtual bool SupportsConcurrentWritingConnectionsInSameTransaction => SupportsConcurrentWritingConnections;
14121412

1413+
/// <summary>
1414+
/// Does this dialect requires null enlistment for reusing a connection after a transaction scope, without
1415+
/// using a new scope?
1416+
/// </summary>
1417+
public virtual bool RequiresNullEnlistment => false;
1418+
14131419
#endregion
14141420

14151421
#region Limit/offset support

src/NHibernate/Dialect/Oracle8iDialect.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,12 @@ public override long TimestampResolutionInTicks
464464
}
465465
}
466466

467+
/// <summary>
468+
/// Does this dialect requires null enlistment for reusing a connection after a transaction scope, without
469+
/// using a new scope?
470+
/// </summary>
471+
public override bool RequiresNullEnlistment => true;
472+
467473
#region Overridden informational metadata
468474

469475
public override bool SupportsEmptyInList

0 commit comments

Comments
 (0)