Skip to content

Commit

Permalink
Port PR 34711 changes from corefx (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wraith2 authored and cheenamalhotra committed Sep 30, 2019
1 parent 29f639a commit aa917d7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -671,67 +671,71 @@ override public void Prepare()
// between entry into Execute* API and the thread obtaining the stateObject.
_pendingCancel = false;


SqlStatistics statistics = null;
statistics = SqlStatistics.StartTimer(Statistics);
try
{
statistics = SqlStatistics.StartTimer(Statistics);

// only prepare if batch with parameters
if (
this.IsPrepared && !this.IsDirty
|| (this.CommandType == CommandType.StoredProcedure)
|| (
(System.Data.CommandType.Text == this.CommandType)
&& (0 == GetParameterCount(_parameters))
)
// only prepare if batch with parameters
if (
this.IsPrepared && !this.IsDirty
|| (this.CommandType == CommandType.StoredProcedure)
|| (
(System.Data.CommandType.Text == this.CommandType)
&& (0 == GetParameterCount(_parameters))
)

)
{
if (null != Statistics)
)
{
Statistics.SafeIncrement(ref Statistics._prepares);
if (null != Statistics)
{
Statistics.SafeIncrement(ref Statistics._prepares);
}
_hiddenPrepare = false;
}
_hiddenPrepare = false;
}
else
{
// Validate the command outside of the try\catch to avoid putting the _stateObj on error
ValidateCommand(isAsync: false);

bool processFinallyBlock = true;
try
else
{
// NOTE: The state object isn't actually needed for this, but it is still here for back-compat (since it does a bunch of checks)
GetStateObject();
// Validate the command outside of the try\catch to avoid putting the _stateObj on error
ValidateCommand(isAsync: false);

// Loop through parameters ensuring that we do not have unspecified types, sizes, scales, or precisions
if (null != _parameters)
bool processFinallyBlock = true;
try
{
int count = _parameters.Count;
for (int i = 0; i < count; ++i)
// NOTE: The state object isn't actually needed for this, but it is still here for back-compat (since it does a bunch of checks)
GetStateObject();

// Loop through parameters ensuring that we do not have unspecified types, sizes, scales, or precisions
if (null != _parameters)
{
_parameters[i].Prepare(this);
int count = _parameters.Count;
for (int i = 0; i < count; ++i)
{
_parameters[i].Prepare(this);
}
}
}

InternalPrepare();
}
catch (Exception e)
{
processFinallyBlock = ADP.IsCatchableExceptionType(e);
throw;
}
finally
{
if (processFinallyBlock)
InternalPrepare();
}
catch (Exception e)
{
processFinallyBlock = ADP.IsCatchableExceptionType(e);
throw;
}
finally
{
_hiddenPrepare = false; // The command is now officially prepared
if (processFinallyBlock)
{
_hiddenPrepare = false; // The command is now officially prepared

ReliablePutStateObject();
ReliablePutStateObject();
}
}
}
}

SqlStatistics.StopTimer(statistics);
finally
{
SqlStatistics.StopTimer(statistics);
}
}

private void InternalPrepare()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,12 @@ internal void Disconnect()
_pMarsPhysicalConObj = null;
}
}

_resetConnectionEvent?.Dispose();
_resetConnectionEvent = null;

_defaultEncoding = null;
_defaultCollation = null;
}

// Fires a single InfoMessageEvent
Expand Down

0 comments on commit aa917d7

Please sign in to comment.