diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlConnection.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlConnection.cs index f67ef15996e0f..9c5d7458f21b7 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlConnection.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlConnection.cs @@ -360,7 +360,9 @@ public Guid ClientConnectionId else { Task reconnectTask = _currentReconnectionTask; - if (reconnectTask != null && !reconnectTask.IsCompleted) + // Connection closed but previously open should return the correct ClientConnectionId + DbConnectionClosedPreviouslyOpened innerConnectionClosed = (InnerConnection as DbConnectionClosedPreviouslyOpened); + if ((reconnectTask != null && !reconnectTask.IsCompleted) || null != innerConnectionClosed) { return _originalConnectionId; } @@ -633,6 +635,7 @@ private void CloseInnerConnection() // The SqlInternalConnectionTds is set to OpenBusy during close, once this happens the cast below will fail and // the command will no longer be cancelable. It might be desirable to be able to cancel the close operation, but this is // outside of the scope of Whidbey RTM. See (SqlCommand::Cancel) for other lock. + _originalConnectionId = ClientConnectionId; InnerConnection.CloseConnection(this, ConnectionFactory); } diff --git a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlStatistics.cs b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlStatistics.cs index 017596642daed..59a437f68d84d 100644 --- a/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlStatistics.cs +++ b/src/libraries/System.Data.SqlClient/src/System/Data/SqlClient/SqlStatistics.cs @@ -212,9 +212,9 @@ internal long SafeIncrement(ref long value) internal void UpdateStatistics() { // update connection time - if (_closeTimestamp >= _openTimestamp) + if (_closeTimestamp >= _openTimestamp && long.MaxValue > _closeTimestamp - _openTimestamp) { - SafeAdd(ref _connectionTime, _closeTimestamp - _openTimestamp); + _connectionTime = _closeTimestamp - _openTimestamp; } else {