@@ -121,8 +121,6 @@ internal sealed partial class TdsParser
121
121
122
122
private bool _is2022 = false;
123
123
124
- private string[] _serverSpn = null;
125
-
126
124
// SqlStatistics
127
125
private SqlStatistics _statistics = null;
128
126
@@ -395,7 +393,6 @@ internal void Connect(ServerInfo serverInfo,
395
393
}
396
394
else
397
395
{
398
- _serverSpn = null;
399
396
SqlClientEventSource.Log.TryTraceEvent("TdsParser.Connect | SEC | Connection Object Id {0}, Authentication Mode: {1}", _connHandler.ObjectID,
400
397
authType == SqlAuthenticationMethod.NotSpecified ? SqlAuthenticationMethod.SqlPassword.ToString() : authType.ToString());
401
398
}
@@ -407,7 +404,6 @@ internal void Connect(ServerInfo serverInfo,
407
404
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> Encryption will be disabled as target server is a SQL Local DB instance.");
408
405
}
409
406
410
- _serverSpn = null;
411
407
_authenticationProvider = null;
412
408
413
409
// AD Integrated behaves like Windows integrated when connecting to a non-fedAuth server
@@ -446,7 +442,7 @@ internal void Connect(ServerInfo serverInfo,
446
442
serverInfo.ExtendedServerName,
447
443
timeout,
448
444
out instanceName,
449
- ref _serverSpn ,
445
+ out var resolvedServerSpn ,
450
446
false,
451
447
true,
452
448
fParallel,
@@ -459,8 +455,6 @@ internal void Connect(ServerInfo serverInfo,
459
455
hostNameInCertificate,
460
456
serverCertificateFilename);
461
457
462
- _authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
463
-
464
458
if (TdsEnums.SNI_SUCCESS != _physicalStateObj.Status)
465
459
{
466
460
_physicalStateObj.AddError(ProcessSNIError(_physicalStateObj));
@@ -546,7 +540,7 @@ internal void Connect(ServerInfo serverInfo,
546
540
serverInfo.ExtendedServerName,
547
541
timeout,
548
542
out instanceName,
549
- ref _serverSpn ,
543
+ out resolvedServerSpn ,
550
544
true,
551
545
true,
552
546
fParallel,
@@ -559,8 +553,6 @@ internal void Connect(ServerInfo serverInfo,
559
553
hostNameInCertificate,
560
554
serverCertificateFilename);
561
555
562
- _authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
563
-
564
556
if (TdsEnums.SNI_SUCCESS != _physicalStateObj.Status)
565
557
{
566
558
_physicalStateObj.AddError(ProcessSNIError(_physicalStateObj));
@@ -599,6 +591,11 @@ internal void Connect(ServerInfo serverInfo,
599
591
}
600
592
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> Prelogin handshake successful");
601
593
594
+ if (_authenticationProvider is { })
595
+ {
596
+ _authenticationProvider.Initialize(serverInfo, _physicalStateObj, this, resolvedServerSpn.Primary, resolvedServerSpn.Secondary);
597
+ }
598
+
602
599
if (_fMARS && marsCapable)
603
600
{
604
601
// if user explicitly disables mars or mars not supported, don't create the session pool
@@ -744,7 +741,7 @@ private void SendPreLoginHandshake(
744
741
745
742
// UNDONE - need to do some length verification to ensure packet does not
746
743
// get too big!!! Not beyond it's max length!
747
-
744
+
748
745
for (int option = (int)PreLoginOptions.VERSION; option < (int)PreLoginOptions.NUMOPT; option++)
749
746
{
750
747
int optionDataSize = 0;
@@ -935,7 +932,7 @@ private PreLoginHandshakeStatus ConsumePreLoginHandshake(
935
932
string serverCertificateFilename)
936
933
{
937
934
// Assign default values
938
- marsCapable = _fMARS;
935
+ marsCapable = _fMARS;
939
936
fedAuthRequired = false;
940
937
Debug.Assert(_physicalStateObj._syncOverAsync, "Should not attempt pends in a synchronous call");
941
938
TdsOperationStatus result = _physicalStateObj.TryReadNetworkPacket();
@@ -2181,7 +2178,7 @@ internal TdsOperationStatus TryRun(RunBehavior runBehavior, SqlCommand cmdHandle
2181
2178
dataStream.BrowseModeInfoConsumed = true;
2182
2179
}
2183
2180
else
2184
- {
2181
+ {
2185
2182
// no dataStream
2186
2183
result = stateObj.TrySkipBytes(tokenLength);
2187
2184
if (result != TdsOperationStatus.Done)
@@ -2195,7 +2192,7 @@ internal TdsOperationStatus TryRun(RunBehavior runBehavior, SqlCommand cmdHandle
2195
2192
case TdsEnums.SQLDONE:
2196
2193
case TdsEnums.SQLDONEPROC:
2197
2194
case TdsEnums.SQLDONEINPROC:
2198
- {
2195
+ {
2199
2196
// RunBehavior can be modified - see SQL BU DT 269516 & 290090
2200
2197
result = TryProcessDone(cmdHandler, dataStream, ref runBehavior, stateObj);
2201
2198
if (result != TdsOperationStatus.Done)
@@ -4122,7 +4119,7 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
4122
4119
{
4123
4120
return result;
4124
4121
}
4125
-
4122
+
4126
4123
byte len;
4127
4124
result = stateObj.TryReadByte(out len);
4128
4125
if (result != TdsOperationStatus.Done)
@@ -4330,7 +4327,7 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
4330
4327
{
4331
4328
return result;
4332
4329
}
4333
-
4330
+
4334
4331
if (rec.collation.IsUTF8)
4335
4332
{ // UTF8 collation
4336
4333
rec.encoding = s_utf8EncodingWithoutBom;
@@ -4790,13 +4787,13 @@ internal TdsOperationStatus TryProcessAltMetaData(int cColumns, TdsParserStateOb
4790
4787
{
4791
4788
// internal meta data class
4792
4789
_SqlMetaData col = altMetaDataSet[i];
4793
-
4790
+
4794
4791
result = stateObj.TryReadByte(out _);
4795
4792
if (result != TdsOperationStatus.Done)
4796
4793
{
4797
4794
return result;
4798
4795
}
4799
-
4796
+
4800
4797
result = stateObj.TryReadUInt16(out _);
4801
4798
if (result != TdsOperationStatus.Done)
4802
4799
{
@@ -5489,7 +5486,7 @@ private TdsOperationStatus TryProcessColInfo(_SqlMetaDataSet columns, SqlDataRea
5489
5486
for (int i = 0; i < columns.Length; i++)
5490
5487
{
5491
5488
_SqlMetaData col = columns[i];
5492
-
5489
+
5493
5490
TdsOperationStatus result = stateObj.TryReadByte(out _);
5494
5491
if (result != TdsOperationStatus.Done)
5495
5492
{
@@ -7394,7 +7391,7 @@ private byte[] SerializeSqlMoney(SqlMoney value, int length, TdsParserStateObjec
7394
7391
7395
7392
private void WriteSqlMoney(SqlMoney value, int length, TdsParserStateObject stateObj)
7396
7393
{
7397
- // UNDONE: can I use SqlMoney.ToInt64()?
7394
+ // UNDONE: can I use SqlMoney.ToInt64()?
7398
7395
int[] bits = decimal.GetBits(value.Value);
7399
7396
7400
7397
// this decimal should be scaled by 10000 (regardless of what the incoming decimal was scaled by)
@@ -9967,7 +9964,7 @@ private Task TDSExecuteRPCAddParameter(TdsParserStateObject stateObj, SqlParamet
9967
9964
9968
9965
WriteUDTMetaData(value, names[0], names[1], names[2], stateObj);
9969
9966
9970
- // UNDONE - re-org to use code below to write value!
9967
+ // UNDONE - re-org to use code below to write value!
9971
9968
if (!isNull)
9972
9969
{
9973
9970
WriteUnsignedLong((ulong)udtVal.Length, stateObj); // PLP length
@@ -12441,7 +12438,7 @@ private Task WriteUnterminatedValue(object value, MetaType type, byte scale, int
12441
12438
case TdsEnums.SQLNVARCHAR:
12442
12439
case TdsEnums.SQLNTEXT:
12443
12440
case TdsEnums.SQLXMLTYPE:
12444
- case TdsEnums.SQLJSON:
12441
+ case TdsEnums.SQLJSON:
12445
12442
{
12446
12443
Debug.Assert(!isDataFeed || (value is TextDataFeed || value is XmlDataFeed), "Value must be a TextReader or XmlReader");
12447
12444
Debug.Assert(isDataFeed || (value is string || value is byte[]), "Value is a byte array or string");
@@ -13666,15 +13663,14 @@ private TdsOperationStatus TryProcessUDTMetaData(SqlMetaDataPriv metaData, TdsPa
13666
13663
+ " _connHandler = {14}\n\t"
13667
13664
+ " _fMARS = {15}\n\t"
13668
13665
+ " _sessionPool = {16}\n\t"
13669
- + " _sniSpnBuffer = {17}\n\t"
13670
- + " _errors = {18}\n\t"
13671
- + " _warnings = {19}\n\t"
13672
- + " _attentionErrors = {20}\n\t"
13673
- + " _attentionWarnings = {21}\n\t"
13674
- + " _statistics = {22}\n\t"
13675
- + " _statisticsIsInTransaction = {23}\n\t"
13676
- + " _fPreserveTransaction = {24}"
13677
- + " _fParallel = {25}"
13666
+ + " _errors = {17}\n\t"
13667
+ + " _warnings = {18}\n\t"
13668
+ + " _attentionErrors = {19}\n\t"
13669
+ + " _attentionWarnings = {20}\n\t"
13670
+ + " _statistics = {21}\n\t"
13671
+ + " _statisticsIsInTransaction = {22}\n\t"
13672
+ + " _fPreserveTransaction = {23}"
13673
+ + " _fParallel = {24}"
13678
13674
;
13679
13675
internal string TraceString()
13680
13676
{
@@ -13697,7 +13693,6 @@ internal string TraceString()
13697
13693
_connHandler == null ? "(null)" : _connHandler.ObjectID.ToString((IFormatProvider)null),
13698
13694
_fMARS ? bool.TrueString : bool.FalseString,
13699
13695
_sessionPool == null ? "(null)" : _sessionPool.TraceString(),
13700
- _serverSpn == null ? "(null)" : _serverSpn.Length.ToString((IFormatProvider)null),
13701
13696
_physicalStateObj != null ? "(null)" : _physicalStateObj.ErrorCount.ToString((IFormatProvider)null),
13702
13697
_physicalStateObj != null ? "(null)" : _physicalStateObj.WarningCount.ToString((IFormatProvider)null),
13703
13698
_physicalStateObj != null ? "(null)" : _physicalStateObj.PreAttentionErrorCount.ToString((IFormatProvider)null),
0 commit comments