@@ -265,17 +265,16 @@ public Byte[] Promote()
265
265
public void Rollback ( SysTx . SinglePhaseEnlistment enlistment )
266
266
{
267
267
Debug . Assert ( null != enlistment , "null enlistment?" ) ;
268
-
269
- SqlInternalConnection connection = GetValidConnection ( ) ;
270
- SqlConnection usersConnection = connection . Connection ;
271
- SqlClientEventSource . Log . TraceEvent ( "<sc.SqlDelegatedTransaction.Rollback|RES|CPOOL> {0}, Connection {1}, aborting transaction." , ObjectID , connection . ObjectID ) ;
272
- RuntimeHelpers . PrepareConstrainedRegions ( ) ;
268
+ SqlInternalConnection connection = null ;
273
269
274
270
try
275
271
{
276
272
#if DEBUG
277
273
TdsParser . ReliabilitySection tdsReliabilitySection = new TdsParser . ReliabilitySection ( ) ;
278
274
275
+ connection = GetValidConnection ( ) ;
276
+ SqlConnection usersConnection = connection . Connection ;
277
+ SqlClientEventSource . Log . TraceEvent ( "<sc.SqlDelegatedTransaction.Rollback|RES|CPOOL> {0}, Connection {1}, aborting transaction." , ObjectID , connection . ObjectID ) ;
279
278
RuntimeHelpers . PrepareConstrainedRegions ( ) ;
280
279
try
281
280
{
@@ -331,27 +330,36 @@ public void Rollback(SysTx.SinglePhaseEnlistment enlistment)
331
330
connection . CleanupConnectionOnTransactionCompletion ( _atomicTransaction ) ;
332
331
enlistment . Aborted ( ) ;
333
332
}
333
+ catch ( System . OutOfMemoryException e )
334
+ {
335
+ usersConnection . Abort ( e ) ;
336
+ throw ;
337
+ }
338
+ catch ( System . StackOverflowException e )
339
+ {
340
+ usersConnection . Abort ( e ) ;
341
+ throw ;
342
+ }
343
+ catch ( System . Threading . ThreadAbortException e )
344
+ {
345
+ usersConnection . Abort ( e ) ;
346
+ throw ;
347
+ }
334
348
#if DEBUG
335
349
finally
336
350
{
337
351
tdsReliabilitySection . Stop ( ) ;
338
352
}
339
353
#endif //DEBUG
340
354
}
341
- catch ( System . OutOfMemoryException e )
355
+ catch ( ObjectDisposedException )
342
356
{
343
- usersConnection . Abort ( e ) ;
344
- throw ;
345
- }
346
- catch ( System . StackOverflowException e )
347
- {
348
- usersConnection . Abort ( e ) ;
349
- throw ;
350
- }
351
- catch ( System . Threading . ThreadAbortException e )
352
- {
353
- usersConnection . Abort ( e ) ;
354
- throw ;
357
+ if ( _atomicTransaction . TransactionInformation . Status == SysTx . TransactionStatus . Active )
358
+ {
359
+ throw ;
360
+ }
361
+ // Do not throw exception if connection is already aborted/ended from another thread,
362
+ // replicate as done in TransactionEnded event handler.
355
363
}
356
364
}
357
365
0 commit comments