Skip to content

Commit 657b1b2

Browse files
committed
undo initialization change
1 parent c56f20e commit 657b1b2

File tree

2 files changed

+31
-30
lines changed
  • src/Microsoft.Data.SqlClient

2 files changed

+31
-30
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@ internal void Connect(
453453
hostNameInCertificate,
454454
serverCertificateFilename);
455455

456+
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
457+
456458
if (TdsEnums.SNI_SUCCESS != _physicalStateObj.Status)
457459
{
458460
_physicalStateObj.AddError(ProcessSNIError(_physicalStateObj));
@@ -467,8 +469,6 @@ internal void Connect(
467469
Debug.Fail("SNI returned status != success, but no error thrown?");
468470
}
469471

470-
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
471-
472472
_server = serverInfo.ResolvedServerName;
473473

474474
if (connHandler.PoolGroupProviderInfo != null)
@@ -552,15 +552,15 @@ internal void Connect(
552552
hostNameInCertificate,
553553
serverCertificateFilename);
554554

555+
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
556+
555557
if (TdsEnums.SNI_SUCCESS != _physicalStateObj.Status)
556558
{
557559
_physicalStateObj.AddError(ProcessSNIError(_physicalStateObj));
558560
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|ERR|SEC> Login failure");
559561
ThrowExceptionAndWarning(_physicalStateObj);
560562
}
561563

562-
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
563-
564564
uint retCode = _physicalStateObj.SniGetConnectionId(ref _connHandler._clientConnectionId);
565565

566566
Debug.Assert(retCode == TdsEnums.SNI_SUCCESS, "Unexpected failure state upon calling SniGetConnectionId");

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

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ internal int ObjectID
163163
// now data length is 1 byte
164164
// First bit is 1 indicating client support failover partner with readonly intent
165165
private static readonly byte[] s_FeatureExtDataAzureSQLSupportFeatureRequest = { 0x01 };
166-
166+
167167
// NOTE: You must take the internal connection's _parserLock before modifying this
168168
internal bool _asyncWrite = false;
169169

@@ -430,6 +430,8 @@ internal void Connect(ServerInfo serverInfo,
430430
// AD Integrated behaves like Windows integrated when connecting to a non-fedAuth server
431431
if (integratedSecurity || authType == SqlAuthenticationMethod.ActiveDirectoryIntegrated)
432432
{
433+
_authenticationProvider = _physicalStateObj.CreateSSPIContextProvider();
434+
433435
if (!string.IsNullOrEmpty(serverInfo.ServerSPN))
434436
{
435437
_serverSpn = serverInfo.ServerSPN;
@@ -441,7 +443,6 @@ internal void Connect(ServerInfo serverInfo,
441443
_serverSpn = string.Empty;
442444
}
443445

444-
_authenticationProvider = _physicalStateObj.CreateSSPIContextProvider();
445446
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> SSPI or Active Directory Authentication Library for SQL Server based integrated authentication");
446447
}
447448
else
@@ -536,6 +537,8 @@ internal void Connect(ServerInfo serverInfo,
536537
FQDNforDNSCache,
537538
hostNameInCertificate);
538539

540+
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
541+
539542
if (TdsEnums.SNI_SUCCESS != _physicalStateObj.Status)
540543
{
541544
_physicalStateObj.AddError(ProcessSNIError(_physicalStateObj));
@@ -550,8 +553,6 @@ internal void Connect(ServerInfo serverInfo,
550553
Debug.Fail("SNI returned status != success, but no error thrown?");
551554
}
552555

553-
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
554-
555556
_server = serverInfo.ResolvedServerName;
556557

557558
if (connHandler.PoolGroupProviderInfo != null)
@@ -636,15 +637,15 @@ internal void Connect(ServerInfo serverInfo,
636637
serverInfo.ResolvedServerName,
637638
hostNameInCertificate);
638639

640+
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
641+
639642
if (TdsEnums.SNI_SUCCESS != _physicalStateObj.Status)
640643
{
641644
_physicalStateObj.AddError(ProcessSNIError(_physicalStateObj));
642645
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|ERR|SEC> Login failure");
643646
ThrowExceptionAndWarning(_physicalStateObj);
644647
}
645648

646-
_authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
647-
648649
uint retCode = SniNativeWrapper.SniGetConnectionId(_physicalStateObj.Handle, ref _connHandler._clientConnectionId);
649650
Debug.Assert(retCode == TdsEnums.SNI_SUCCESS, "Unexpected failure state upon calling SniGetConnectionId");
650651
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> Sending prelogin handshake");
@@ -3390,7 +3391,7 @@ private TdsOperationStatus TryProcessDone(SqlCommand cmd, SqlDataReader reader,
33903391
Debug.Assert(!((sqlTransaction != null && _distributedTransaction != null) ||
33913392
(_userStartedLocalTransaction != null && _distributedTransaction != null))
33923393
, "ProcessDone - have both distributed and local transactions not null!");
3393-
*/
3394+
*/
33943395
// WebData 112722
33953396

33963397
stateObj.DecrementOpenResultCount();
@@ -3877,8 +3878,8 @@ private TdsOperationStatus TryProcessSessionState(TdsParserStateObject stateObj,
38773878
if (!recoverable)
38783879
{
38793880
checked
3880-
{
3881-
sdata._unrecoverableStatesCount++;
3881+
{
3882+
sdata._unrecoverableStatesCount++;
38823883
}
38833884
}
38843885
}
@@ -3899,8 +3900,8 @@ private TdsOperationStatus TryProcessSessionState(TdsParserStateObject stateObj,
38993900
else
39003901
{
39013902
checked
3902-
{
3903-
sdata._unrecoverableStatesCount++;
3903+
{
3904+
sdata._unrecoverableStatesCount++;
39043905
}
39053906
}
39063907
sv._recoverable = recoverable;
@@ -3979,29 +3980,29 @@ private TdsOperationStatus TryProcessLoginAck(TdsParserStateObject stateObj, out
39793980
{
39803981
case TdsEnums.SQL2005_MAJOR << 24 | TdsEnums.SQL2005_RTM_MINOR: // 2005
39813982
if (increment != TdsEnums.SQL2005_INCREMENT)
3982-
{
3983-
throw SQL.InvalidTDSVersion();
3983+
{
3984+
throw SQL.InvalidTDSVersion();
39843985
}
39853986
_is2005 = true;
39863987
break;
39873988
case TdsEnums.SQL2008_MAJOR << 24 | TdsEnums.SQL2008_MINOR:
39883989
if (increment != TdsEnums.SQL2008_INCREMENT)
3989-
{
3990-
throw SQL.InvalidTDSVersion();
3990+
{
3991+
throw SQL.InvalidTDSVersion();
39913992
}
39923993
_is2008 = true;
39933994
break;
39943995
case TdsEnums.SQL2012_MAJOR << 24 | TdsEnums.SQL2012_MINOR:
39953996
if (increment != TdsEnums.SQL2012_INCREMENT)
3996-
{
3997-
throw SQL.InvalidTDSVersion();
3997+
{
3998+
throw SQL.InvalidTDSVersion();
39983999
}
39994000
_is2012 = true;
40004001
break;
40014002
case TdsEnums.TDS8_MAJOR << 24 | TdsEnums.TDS8_MINOR:
40024003
if (increment != TdsEnums.TDS8_INCREMENT)
4003-
{
4004-
throw SQL.InvalidTDSVersion();
4004+
{
4005+
throw SQL.InvalidTDSVersion();
40054006
}
40064007
_is2022 = true;
40074008
break;
@@ -5934,7 +5935,7 @@ private TdsOperationStatus TryProcessColInfo(_SqlMetaDataSet columns, SqlDataRea
59345935
for (int i = 0; i < columns.Length; i++)
59355936
{
59365937
_SqlMetaData col = columns[i];
5937-
5938+
59385939
result = stateObj.TryReadByte(out _);
59395940
if (result != TdsOperationStatus.Done)
59405941
{
@@ -6471,7 +6472,7 @@ private TdsOperationStatus TryReadSqlStringValue(SqlBuffer value, byte type, int
64716472
char[] cc = null;
64726473
bool buffIsRented = false;
64736474
result = TryReadPlpUnicodeChars(ref cc, 0, length >> 1, stateObj, out length, supportRentedBuff: true, rentedBuff: ref buffIsRented);
6474-
6475+
64756476
if (result == TdsOperationStatus.Done)
64766477
{
64776478
if (length > 0)
@@ -11370,7 +11371,7 @@ internal object EncryptColumnValue(object value, SqlMetaDataPriv metadata, strin
1137011371
actualLengthInBytes = (isSqlType) ? ((SqlBinary)value).Length : ((byte[])value).Length;
1137111372
if (metadata.baseTI.length > 0 &&
1137211373
actualLengthInBytes > metadata.baseTI.length)
11373-
{
11374+
{
1137411375
// see comments above
1137511376
actualLengthInBytes = metadata.baseTI.length;
1137611377
}
@@ -12278,7 +12279,7 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
1227812279
_parser.WriteInt(count, _stateObj); // write length of chunk
1227912280
task = _stateObj.WriteByteArray(buffer, count, offset, canAccumulate: false);
1228012281
}
12281-
12282+
1228212283
return task ?? Task.CompletedTask;
1228312284
}
1228412285
catch (System.OutOfMemoryException)
@@ -12511,7 +12512,7 @@ private async Task WriteTextFeed(TextDataFeed feed, Encoding encoding, bool need
1251112512
char[] inBuff = ArrayPool<char>.Shared.Rent(constTextBufferSize);
1251212513

1251312514
encoding = encoding ?? new UnicodeEncoding(false, false);
12514-
12515+
1251512516
using (ConstrainedTextWriter writer = new ConstrainedTextWriter(new StreamWriter(new TdsOutputStream(this, stateObj, null), encoding), size))
1251612517
{
1251712518
if (needBom)
@@ -13429,7 +13430,7 @@ internal TdsOperationStatus TryReadPlpUnicodeChars(
1342913430
int charsRead = 0;
1343013431
int charsLeft = 0;
1343113432
char[] newbuf;
13432-
13433+
1343313434
if (stateObj._longlen == 0)
1343413435
{
1343513436
Debug.Assert(stateObj._longlenleft == 0);
@@ -13546,7 +13547,7 @@ internal TdsOperationStatus TryReadPlpUnicodeChars(
1354613547
totalCharsRead++;
1354713548
}
1354813549
if (stateObj._longlenleft == 0)
13549-
{
13550+
{
1355013551
// Read the next chunk or cleanup state if hit the end
1355113552
result = stateObj.TryReadPlpLength(false, out _);
1355213553
if (result != TdsOperationStatus.Done)

0 commit comments

Comments
 (0)