@@ -121,8 +121,6 @@ internal sealed partial class TdsParser
121121
122122 private bool _is2022 = false;
123123
124- private string[] _serverSpn = null;
125-
126124 // SqlStatistics
127125 private SqlStatistics _statistics = null;
128126
@@ -395,7 +393,6 @@ internal void Connect(ServerInfo serverInfo,
395393 }
396394 else
397395 {
398- _serverSpn = null;
399396 SqlClientEventSource.Log.TryTraceEvent("TdsParser.Connect | SEC | Connection Object Id {0}, Authentication Mode: {1}", _connHandler.ObjectID,
400397 authType == SqlAuthenticationMethod.NotSpecified ? SqlAuthenticationMethod.SqlPassword.ToString() : authType.ToString());
401398 }
@@ -407,7 +404,6 @@ internal void Connect(ServerInfo serverInfo,
407404 SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> Encryption will be disabled as target server is a SQL Local DB instance.");
408405 }
409406
410- _serverSpn = null;
411407 _authenticationProvider = null;
412408
413409 // AD Integrated behaves like Windows integrated when connecting to a non-fedAuth server
@@ -446,7 +442,7 @@ internal void Connect(ServerInfo serverInfo,
446442 serverInfo.ExtendedServerName,
447443 timeout,
448444 out instanceName,
449- ref _serverSpn ,
445+ out var resolvedServerSpn ,
450446 false,
451447 true,
452448 fParallel,
@@ -459,8 +455,6 @@ internal void Connect(ServerInfo serverInfo,
459455 hostNameInCertificate,
460456 serverCertificateFilename);
461457
462- _authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
463-
464458 if (TdsEnums.SNI_SUCCESS != _physicalStateObj.Status)
465459 {
466460 _physicalStateObj.AddError(ProcessSNIError(_physicalStateObj));
@@ -546,7 +540,7 @@ internal void Connect(ServerInfo serverInfo,
546540 serverInfo.ExtendedServerName,
547541 timeout,
548542 out instanceName,
549- ref _serverSpn ,
543+ out resolvedServerSpn ,
550544 true,
551545 true,
552546 fParallel,
@@ -559,8 +553,6 @@ internal void Connect(ServerInfo serverInfo,
559553 hostNameInCertificate,
560554 serverCertificateFilename);
561555
562- _authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
563-
564556 if (TdsEnums.SNI_SUCCESS != _physicalStateObj.Status)
565557 {
566558 _physicalStateObj.AddError(ProcessSNIError(_physicalStateObj));
@@ -599,6 +591,11 @@ internal void Connect(ServerInfo serverInfo,
599591 }
600592 SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> Prelogin handshake successful");
601593
594+ if (_authenticationProvider is { })
595+ {
596+ _authenticationProvider.Initialize(serverInfo, _physicalStateObj, this, resolvedServerSpn.Primary, resolvedServerSpn.Secondary);
597+ }
598+
602599 if (_fMARS && marsCapable)
603600 {
604601 // if user explicitly disables mars or mars not supported, don't create the session pool
@@ -744,7 +741,7 @@ private void SendPreLoginHandshake(
744741
745742 // UNDONE - need to do some length verification to ensure packet does not
746743 // get too big!!! Not beyond it's max length!
747-
744+
748745 for (int option = (int)PreLoginOptions.VERSION; option < (int)PreLoginOptions.NUMOPT; option++)
749746 {
750747 int optionDataSize = 0;
@@ -935,7 +932,7 @@ private PreLoginHandshakeStatus ConsumePreLoginHandshake(
935932 string serverCertificateFilename)
936933 {
937934 // Assign default values
938- marsCapable = _fMARS;
935+ marsCapable = _fMARS;
939936 fedAuthRequired = false;
940937 Debug.Assert(_physicalStateObj._syncOverAsync, "Should not attempt pends in a synchronous call");
941938 TdsOperationStatus result = _physicalStateObj.TryReadNetworkPacket();
@@ -2181,7 +2178,7 @@ internal TdsOperationStatus TryRun(RunBehavior runBehavior, SqlCommand cmdHandle
21812178 dataStream.BrowseModeInfoConsumed = true;
21822179 }
21832180 else
2184- {
2181+ {
21852182 // no dataStream
21862183 result = stateObj.TrySkipBytes(tokenLength);
21872184 if (result != TdsOperationStatus.Done)
@@ -2195,7 +2192,7 @@ internal TdsOperationStatus TryRun(RunBehavior runBehavior, SqlCommand cmdHandle
21952192 case TdsEnums.SQLDONE:
21962193 case TdsEnums.SQLDONEPROC:
21972194 case TdsEnums.SQLDONEINPROC:
2198- {
2195+ {
21992196 // RunBehavior can be modified - see SQL BU DT 269516 & 290090
22002197 result = TryProcessDone(cmdHandler, dataStream, ref runBehavior, stateObj);
22012198 if (result != TdsOperationStatus.Done)
@@ -4122,7 +4119,7 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
41224119 {
41234120 return result;
41244121 }
4125-
4122+
41264123 byte len;
41274124 result = stateObj.TryReadByte(out len);
41284125 if (result != TdsOperationStatus.Done)
@@ -4330,7 +4327,7 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
43304327 {
43314328 return result;
43324329 }
4333-
4330+
43344331 if (rec.collation.IsUTF8)
43354332 { // UTF8 collation
43364333 rec.encoding = s_utf8EncodingWithoutBom;
@@ -4790,13 +4787,13 @@ internal TdsOperationStatus TryProcessAltMetaData(int cColumns, TdsParserStateOb
47904787 {
47914788 // internal meta data class
47924789 _SqlMetaData col = altMetaDataSet[i];
4793-
4790+
47944791 result = stateObj.TryReadByte(out _);
47954792 if (result != TdsOperationStatus.Done)
47964793 {
47974794 return result;
47984795 }
4799-
4796+
48004797 result = stateObj.TryReadUInt16(out _);
48014798 if (result != TdsOperationStatus.Done)
48024799 {
@@ -5489,7 +5486,7 @@ private TdsOperationStatus TryProcessColInfo(_SqlMetaDataSet columns, SqlDataRea
54895486 for (int i = 0; i < columns.Length; i++)
54905487 {
54915488 _SqlMetaData col = columns[i];
5492-
5489+
54935490 TdsOperationStatus result = stateObj.TryReadByte(out _);
54945491 if (result != TdsOperationStatus.Done)
54955492 {
@@ -7394,7 +7391,7 @@ private byte[] SerializeSqlMoney(SqlMoney value, int length, TdsParserStateObjec
73947391
73957392 private void WriteSqlMoney(SqlMoney value, int length, TdsParserStateObject stateObj)
73967393 {
7397- // UNDONE: can I use SqlMoney.ToInt64()?
7394+ // UNDONE: can I use SqlMoney.ToInt64()?
73987395 int[] bits = decimal.GetBits(value.Value);
73997396
74007397 // 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
99679964
99689965 WriteUDTMetaData(value, names[0], names[1], names[2], stateObj);
99699966
9970- // UNDONE - re-org to use code below to write value!
9967+ // UNDONE - re-org to use code below to write value!
99719968 if (!isNull)
99729969 {
99739970 WriteUnsignedLong((ulong)udtVal.Length, stateObj); // PLP length
@@ -12441,7 +12438,7 @@ private Task WriteUnterminatedValue(object value, MetaType type, byte scale, int
1244112438 case TdsEnums.SQLNVARCHAR:
1244212439 case TdsEnums.SQLNTEXT:
1244312440 case TdsEnums.SQLXMLTYPE:
12444- case TdsEnums.SQLJSON:
12441+ case TdsEnums.SQLJSON:
1244512442 {
1244612443 Debug.Assert(!isDataFeed || (value is TextDataFeed || value is XmlDataFeed), "Value must be a TextReader or XmlReader");
1244712444 Debug.Assert(isDataFeed || (value is string || value is byte[]), "Value is a byte array or string");
@@ -13659,15 +13656,14 @@ private TdsOperationStatus TryProcessUDTMetaData(SqlMetaDataPriv metaData, TdsPa
1365913656 + " _connHandler = {14}\n\t"
1366013657 + " _fMARS = {15}\n\t"
1366113658 + " _sessionPool = {16}\n\t"
13662- + " _sniSpnBuffer = {17}\n\t"
13663- + " _errors = {18}\n\t"
13664- + " _warnings = {19}\n\t"
13665- + " _attentionErrors = {20}\n\t"
13666- + " _attentionWarnings = {21}\n\t"
13667- + " _statistics = {22}\n\t"
13668- + " _statisticsIsInTransaction = {23}\n\t"
13669- + " _fPreserveTransaction = {24}"
13670- + " _fParallel = {25}"
13659+ + " _errors = {17}\n\t"
13660+ + " _warnings = {18}\n\t"
13661+ + " _attentionErrors = {19}\n\t"
13662+ + " _attentionWarnings = {20}\n\t"
13663+ + " _statistics = {21}\n\t"
13664+ + " _statisticsIsInTransaction = {22}\n\t"
13665+ + " _fPreserveTransaction = {23}"
13666+ + " _fParallel = {24}"
1367113667 ;
1367213668 internal string TraceString()
1367313669 {
@@ -13690,7 +13686,6 @@ internal string TraceString()
1369013686 _connHandler == null ? "(null)" : _connHandler.ObjectID.ToString((IFormatProvider)null),
1369113687 _fMARS ? bool.TrueString : bool.FalseString,
1369213688 _sessionPool == null ? "(null)" : _sessionPool.TraceString(),
13693- _serverSpn == null ? "(null)" : _serverSpn.Length.ToString((IFormatProvider)null),
1369413689 _physicalStateObj != null ? "(null)" : _physicalStateObj.ErrorCount.ToString((IFormatProvider)null),
1369513690 _physicalStateObj != null ? "(null)" : _physicalStateObj.WarningCount.ToString((IFormatProvider)null),
1369613691 _physicalStateObj != null ? "(null)" : _physicalStateObj.PreAttentionErrorCount.ToString((IFormatProvider)null),
0 commit comments