if (_stateObj != null)
{
- CleanUpStateObjectOnError();
+ CleanUpStateObject();
}
}
catch (OutOfMemoryException)
}
// Cleans the stateobj. Used in a number of places, specially in exceptions.
- private void CleanUpStateObjectOnError()
+ private void CleanUpStateObject(bool isCancelRequested = true)
{
if (_stateObj != null)
{
_stateObj.ResetBuffer();
_stateObj.ResetPacketCounters();
// If _parser is closed, sending attention will raise debug assertion, so we avoid it (but not calling CancelRequest).
- if (_parser.State == TdsParserState.OpenNotLoggedIn || _parser.State == TdsParserState.OpenLoggedIn)
+ if (isCancelRequested && (_parser.State == TdsParserState.OpenNotLoggedIn || _parser.State == TdsParserState.OpenLoggedIn))
{
_stateObj.CancelRequest();
}
_localColumnMappings = null;
try
{
- CleanUpStateObjectOnError();
+ CleanUpStateObject();
}
finally
{
_localColumnMappings = null;
try
{
- CleanUpStateObjectOnError();
+ CleanUpStateObject(isCancelRequested: false);
}
finally
{
try
{
- CleanUpStateObjectOnError();
+ CleanUpStateObject(isCancelRequested: false);
}
catch (Exception cleanupEx)
{
- Debug.Fail("Unexpected exception during CleanUpstateObjectOnError (ignored)", cleanupEx.ToString());
+ Debug.Fail($"Unexpected exception during {nameof(CleanUpStateObject)} (ignored)", cleanupEx.ToString());
}
if (source != null)
try
{
- CleanUpStateObjectOnError();
+ CleanUpStateObject();
}
catch (Exception cleanupEx)
{
- Debug.Fail("Unexpected exception during CleanUpstateObjectOnError (ignored)", cleanupEx.ToString());
+ Debug.Fail($"Unexpected exception during {nameof(CleanUpStateObject)} (ignored)", cleanupEx.ToString());
}
if (source != null)