diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs index e1a86fa0e7..472edf6888 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs @@ -520,8 +520,19 @@ internal void DeactivateConnection() SqlClientEventSource.Log.TryPoolerTraceEvent(" {0}, Deactivating", ObjectID); #if DEBUG - int activateCount = Interlocked.Decrement(ref _activateCount); - Debug.Assert(activateCount == 0, "activated multiple times?"); + int origCount, newCount; + do + { + origCount = _activateCount; + + if (origCount == 0) + { + break; + } + + newCount = origCount - 1; + } + while (Interlocked.CompareExchange(ref _activateCount, newCount, origCount) != origCount); #endif SqlClientEventSource.Metrics.ExitActiveConnection();