Skip to content

Pooled connection corrupted after TransactionScope rollback with failed DTC promotion #4001

@cert-kkrawczyk

Description

@cert-kkrawczyk

Describe the bug

When a TransactionScope containing two enlisted connections rolls back (due to failed DTC promotion on .NET 8+ where ImplicitDistributedTransactions is disabled by default), the first connection is returned to the pool in a corrupted state. The pool does not discard it — subsequent Open() succeeds (State == Open), but BeginTransaction() throws:

Exception message:
System.InvalidOperationException: The requested operation cannot be completed because the connection has been broken.

Stack trace:
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest, String name, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
   at Microsoft.Data.SqlClient.SqlInternalConnection.BeginSqlTransaction(IsolationLevel iso, String transactionName, Boolean shouldReconnect)
   at Microsoft.Data.SqlClient.SqlConnection.BeginTransaction(IsolationLevel iso, String transactionName)
   at Microsoft.Data.SqlClient.SqlConnection.BeginTransaction(IsolationLevel iso)
   at Microsoft.Data.SqlClient.SqlConnection.BeginDbTransaction(IsolationLevel isolationLevel)

Pooling=false eliminates problem.

To reproduce

Se attached console application that reproduces issue

Expected behavior

Corrupted connections should be discarded by the pool, not returned on next Open().

Further technical details

Microsoft.Data.SqlClient version: 6.1.4
.NET target: .NET 10.0

Program.zip

Related: #2285 — same exception on pooled connections with TransactionScope, no repro available.

Metadata

Metadata

Labels

Repro Available ✔️Issues that are reproducible with repro provided.

Type

Projects

Status

Investigating

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions