Skip to content

Commit 65a6ddf

Browse files
committed
move serverSpn to be local
1 parent fbd62e0 commit 65a6ddf

File tree

2 files changed

+15
-17
lines changed
  • src/Microsoft.Data.SqlClient

2 files changed

+15
-17
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -386,6 +384,8 @@ internal void Connect(ServerInfo serverInfo,
386384

387385
uint sniStatus = TdsParserStateObjectFactory.Singleton.SNIStatus;
388386

387+
string[] serverSpn = null;
388+
389389
if (sniStatus != TdsEnums.SNI_SUCCESS)
390390
{
391391
_physicalStateObj.AddError(ProcessSNIError(_physicalStateObj));
@@ -395,7 +395,7 @@ internal void Connect(ServerInfo serverInfo,
395395
}
396396
else
397397
{
398-
_serverSpn = null;
398+
serverSpn = null;
399399
SqlClientEventSource.Log.TryTraceEvent("TdsParser.Connect | SEC | Connection Object Id {0}, Authentication Mode: {1}", _connHandler.ObjectID,
400400
authType == SqlAuthenticationMethod.NotSpecified ? SqlAuthenticationMethod.SqlPassword.ToString() : authType.ToString());
401401
}
@@ -407,7 +407,7 @@ internal void Connect(ServerInfo serverInfo,
407407
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> Encryption will be disabled as target server is a SQL Local DB instance.");
408408
}
409409

410-
_serverSpn = null;
410+
serverSpn = null;
411411
_authenticationProvider = null;
412412

413413
// AD Integrated behaves like Windows integrated when connecting to a non-fedAuth server
@@ -446,7 +446,7 @@ internal void Connect(ServerInfo serverInfo,
446446
serverInfo.ExtendedServerName,
447447
timeout,
448448
out instanceName,
449-
ref _serverSpn,
449+
ref serverSpn,
450450
false,
451451
true,
452452
fParallel,
@@ -544,7 +544,7 @@ internal void Connect(ServerInfo serverInfo,
544544
serverInfo.ExtendedServerName,
545545
timeout,
546546
out instanceName,
547-
ref _serverSpn,
547+
ref serverSpn,
548548
true,
549549
true,
550550
fParallel,
@@ -595,7 +595,7 @@ internal void Connect(ServerInfo serverInfo,
595595
}
596596
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> Prelogin handshake successful");
597597

598-
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this, _serverSpn);
598+
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this, serverSpn);
599599

600600
if (_fMARS && marsCapable)
601601
{
@@ -13585,7 +13585,6 @@ internal string TraceString()
1358513585
_connHandler == null ? "(null)" : _connHandler.ObjectID.ToString((IFormatProvider)null),
1358613586
_fMARS ? bool.TrueString : bool.FalseString,
1358713587
_sessionPool == null ? "(null)" : _sessionPool.TraceString(),
13588-
_serverSpn == null ? "(null)" : _serverSpn.Length.ToString((IFormatProvider)null),
1358913588
_physicalStateObj != null ? "(null)" : _physicalStateObj.ErrorCount.ToString((IFormatProvider)null),
1359013589
_physicalStateObj != null ? "(null)" : _physicalStateObj.WarningCount.ToString((IFormatProvider)null),
1359113590
_physicalStateObj != null ? "(null)" : _physicalStateObj.PreAttentionErrorCount.ToString((IFormatProvider)null),

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

@@ -396,6 +394,8 @@ internal void Connect(ServerInfo serverInfo,
396394
Debug.Fail("SNI returned status != success, but no error thrown?");
397395
}
398396

397+
string serverSpn = null;
398+
399399
//Create LocalDB instance if necessary
400400
if (connHandler.ConnectionOptions.LocalDBInstance != null)
401401
{
@@ -415,21 +415,21 @@ internal void Connect(ServerInfo serverInfo,
415415

416416
if (!string.IsNullOrEmpty(serverInfo.ServerSPN))
417417
{
418-
_serverSpn = serverInfo.ServerSPN;
418+
serverSpn = serverInfo.ServerSPN;
419419
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> Server SPN `{0}` from the connection string is used.", serverInfo.ServerSPN);
420420
}
421421
else
422422
{
423423
// Empty signifies to interop layer that SPN needs to be generated
424-
_serverSpn = string.Empty;
424+
serverSpn = string.Empty;
425425
}
426426

427427
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> SSPI or Active Directory Authentication Library for SQL Server based integrated authentication");
428428
}
429429
else
430430
{
431431
_authenticationProvider = null;
432-
_serverSpn = null;
432+
serverSpn = null;
433433

434434
switch (authType)
435435
{
@@ -508,7 +508,7 @@ internal void Connect(ServerInfo serverInfo,
508508
serverInfo.ExtendedServerName,
509509
timeout,
510510
out instanceName,
511-
ref _serverSpn,
511+
ref serverSpn,
512512
false,
513513
true,
514514
fParallel,
@@ -600,7 +600,7 @@ internal void Connect(ServerInfo serverInfo,
600600
serverInfo.ExtendedServerName,
601601
timeout,
602602
out instanceName,
603-
ref _serverSpn,
603+
ref serverSpn,
604604
true,
605605
true,
606606
fParallel,
@@ -644,7 +644,7 @@ internal void Connect(ServerInfo serverInfo,
644644
}
645645
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> Prelogin handshake successful");
646646

647-
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this, _serverSpn);
647+
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this, serverSpn);
648648

649649
if (_fMARS && marsCapable)
650650
{
@@ -13698,7 +13698,6 @@ internal string TraceString()
1369813698
_connHandler == null ? "(null)" : _connHandler.ObjectID.ToString((IFormatProvider)null),
1369913699
_fMARS ? bool.TrueString : bool.FalseString,
1370013700
_sessionPool == null ? "(null)" : _sessionPool.TraceString(),
13701-
_serverSpn == null ? "(null)" : _serverSpn.Length.ToString((IFormatProvider)null),
1370213701
_physicalStateObj != null ? "(null)" : _physicalStateObj.ErrorCount.ToString((IFormatProvider)null),
1370313702
_physicalStateObj != null ? "(null)" : _physicalStateObj.WarningCount.ToString((IFormatProvider)null),
1370413703
_physicalStateObj != null ? "(null)" : _physicalStateObj.PreAttentionErrorCount.ToString((IFormatProvider)null),

0 commit comments

Comments
 (0)