Skip to content

Commit aa917d7

Browse files
Wraith2cheenamalhotra
authored andcommitted
Port PR 34711 changes from corefx (#232)
1 parent 29f639a commit aa917d7

File tree

2 files changed

+55
-45
lines changed

2 files changed

+55
-45
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -671,67 +671,71 @@ override public void Prepare()
671671
// between entry into Execute* API and the thread obtaining the stateObject.
672672
_pendingCancel = false;
673673

674-
675674
SqlStatistics statistics = null;
676-
statistics = SqlStatistics.StartTimer(Statistics);
675+
try
676+
{
677+
statistics = SqlStatistics.StartTimer(Statistics);
677678

678-
// only prepare if batch with parameters
679-
if (
680-
this.IsPrepared && !this.IsDirty
681-
|| (this.CommandType == CommandType.StoredProcedure)
682-
|| (
683-
(System.Data.CommandType.Text == this.CommandType)
684-
&& (0 == GetParameterCount(_parameters))
685-
)
679+
// only prepare if batch with parameters
680+
if (
681+
this.IsPrepared && !this.IsDirty
682+
|| (this.CommandType == CommandType.StoredProcedure)
683+
|| (
684+
(System.Data.CommandType.Text == this.CommandType)
685+
&& (0 == GetParameterCount(_parameters))
686+
)
686687

687-
)
688-
{
689-
if (null != Statistics)
688+
)
690689
{
691-
Statistics.SafeIncrement(ref Statistics._prepares);
690+
if (null != Statistics)
691+
{
692+
Statistics.SafeIncrement(ref Statistics._prepares);
693+
}
694+
_hiddenPrepare = false;
692695
}
693-
_hiddenPrepare = false;
694-
}
695-
else
696-
{
697-
// Validate the command outside of the try\catch to avoid putting the _stateObj on error
698-
ValidateCommand(isAsync: false);
699-
700-
bool processFinallyBlock = true;
701-
try
696+
else
702697
{
703-
// 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)
704-
GetStateObject();
698+
// Validate the command outside of the try\catch to avoid putting the _stateObj on error
699+
ValidateCommand(isAsync: false);
705700

706-
// Loop through parameters ensuring that we do not have unspecified types, sizes, scales, or precisions
707-
if (null != _parameters)
701+
bool processFinallyBlock = true;
702+
try
708703
{
709-
int count = _parameters.Count;
710-
for (int i = 0; i < count; ++i)
704+
// 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)
705+
GetStateObject();
706+
707+
// Loop through parameters ensuring that we do not have unspecified types, sizes, scales, or precisions
708+
if (null != _parameters)
711709
{
712-
_parameters[i].Prepare(this);
710+
int count = _parameters.Count;
711+
for (int i = 0; i < count; ++i)
712+
{
713+
_parameters[i].Prepare(this);
714+
}
713715
}
714-
}
715716

716-
InternalPrepare();
717-
}
718-
catch (Exception e)
719-
{
720-
processFinallyBlock = ADP.IsCatchableExceptionType(e);
721-
throw;
722-
}
723-
finally
724-
{
725-
if (processFinallyBlock)
717+
InternalPrepare();
718+
}
719+
catch (Exception e)
720+
{
721+
processFinallyBlock = ADP.IsCatchableExceptionType(e);
722+
throw;
723+
}
724+
finally
726725
{
727-
_hiddenPrepare = false; // The command is now officially prepared
726+
if (processFinallyBlock)
727+
{
728+
_hiddenPrepare = false; // The command is now officially prepared
728729

729-
ReliablePutStateObject();
730+
ReliablePutStateObject();
731+
}
730732
}
731733
}
732734
}
733-
734-
SqlStatistics.StopTimer(statistics);
735+
finally
736+
{
737+
SqlStatistics.StopTimer(statistics);
738+
}
735739
}
736740

737741
private void InternalPrepare()

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,12 @@ internal void Disconnect()
10181018
_pMarsPhysicalConObj = null;
10191019
}
10201020
}
1021+
1022+
_resetConnectionEvent?.Dispose();
1023+
_resetConnectionEvent = null;
1024+
1025+
_defaultEncoding = null;
1026+
_defaultCollation = null;
10211027
}
10221028

10231029
// Fires a single InfoMessageEvent

0 commit comments

Comments
 (0)