@@ -163,7 +163,7 @@ internal int ObjectID
163
163
// now data length is 1 byte
164
164
// First bit is 1 indicating client support failover partner with readonly intent
165
165
private static readonly byte[] s_FeatureExtDataAzureSQLSupportFeatureRequest = { 0x01 };
166
-
166
+
167
167
// NOTE: You must take the internal connection's _parserLock before modifying this
168
168
internal bool _asyncWrite = false;
169
169
@@ -430,6 +430,8 @@ internal void Connect(ServerInfo serverInfo,
430
430
// AD Integrated behaves like Windows integrated when connecting to a non-fedAuth server
431
431
if (integratedSecurity || authType == SqlAuthenticationMethod.ActiveDirectoryIntegrated)
432
432
{
433
+ _authenticationProvider = _physicalStateObj.CreateSSPIContextProvider();
434
+
433
435
if (!string.IsNullOrEmpty(serverInfo.ServerSPN))
434
436
{
435
437
_serverSpn = serverInfo.ServerSPN;
@@ -441,7 +443,6 @@ internal void Connect(ServerInfo serverInfo,
441
443
_serverSpn = string.Empty;
442
444
}
443
445
444
- _authenticationProvider = _physicalStateObj.CreateSSPIContextProvider();
445
446
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> SSPI or Active Directory Authentication Library for SQL Server based integrated authentication");
446
447
}
447
448
else
@@ -536,6 +537,8 @@ internal void Connect(ServerInfo serverInfo,
536
537
FQDNforDNSCache,
537
538
hostNameInCertificate);
538
539
540
+ _authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
541
+
539
542
if (TdsEnums.SNI_SUCCESS != _physicalStateObj.Status)
540
543
{
541
544
_physicalStateObj.AddError(ProcessSNIError(_physicalStateObj));
@@ -550,8 +553,6 @@ internal void Connect(ServerInfo serverInfo,
550
553
Debug.Fail("SNI returned status != success, but no error thrown?");
551
554
}
552
555
553
- _authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
554
-
555
556
_server = serverInfo.ResolvedServerName;
556
557
557
558
if (connHandler.PoolGroupProviderInfo != null)
@@ -636,15 +637,15 @@ internal void Connect(ServerInfo serverInfo,
636
637
serverInfo.ResolvedServerName,
637
638
hostNameInCertificate);
638
639
640
+ _authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
641
+
639
642
if (TdsEnums.SNI_SUCCESS != _physicalStateObj.Status)
640
643
{
641
644
_physicalStateObj.AddError(ProcessSNIError(_physicalStateObj));
642
645
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|ERR|SEC> Login failure");
643
646
ThrowExceptionAndWarning(_physicalStateObj);
644
647
}
645
648
646
- _authenticationProvider?.Initialize(serverInfo, _physicalStateObj, this);
647
-
648
649
uint retCode = SniNativeWrapper.SniGetConnectionId(_physicalStateObj.Handle, ref _connHandler._clientConnectionId);
649
650
Debug.Assert(retCode == TdsEnums.SNI_SUCCESS, "Unexpected failure state upon calling SniGetConnectionId");
650
651
SqlClientEventSource.Log.TryTraceEvent("<sc.TdsParser.Connect|SEC> Sending prelogin handshake");
@@ -3390,7 +3391,7 @@ private TdsOperationStatus TryProcessDone(SqlCommand cmd, SqlDataReader reader,
3390
3391
Debug.Assert(!((sqlTransaction != null && _distributedTransaction != null) ||
3391
3392
(_userStartedLocalTransaction != null && _distributedTransaction != null))
3392
3393
, "ProcessDone - have both distributed and local transactions not null!");
3393
- */
3394
+ */
3394
3395
// WebData 112722
3395
3396
3396
3397
stateObj.DecrementOpenResultCount();
@@ -3877,8 +3878,8 @@ private TdsOperationStatus TryProcessSessionState(TdsParserStateObject stateObj,
3877
3878
if (!recoverable)
3878
3879
{
3879
3880
checked
3880
- {
3881
- sdata._unrecoverableStatesCount++;
3881
+ {
3882
+ sdata._unrecoverableStatesCount++;
3882
3883
}
3883
3884
}
3884
3885
}
@@ -3899,8 +3900,8 @@ private TdsOperationStatus TryProcessSessionState(TdsParserStateObject stateObj,
3899
3900
else
3900
3901
{
3901
3902
checked
3902
- {
3903
- sdata._unrecoverableStatesCount++;
3903
+ {
3904
+ sdata._unrecoverableStatesCount++;
3904
3905
}
3905
3906
}
3906
3907
sv._recoverable = recoverable;
@@ -3979,29 +3980,29 @@ private TdsOperationStatus TryProcessLoginAck(TdsParserStateObject stateObj, out
3979
3980
{
3980
3981
case TdsEnums.SQL2005_MAJOR << 24 | TdsEnums.SQL2005_RTM_MINOR: // 2005
3981
3982
if (increment != TdsEnums.SQL2005_INCREMENT)
3982
- {
3983
- throw SQL.InvalidTDSVersion();
3983
+ {
3984
+ throw SQL.InvalidTDSVersion();
3984
3985
}
3985
3986
_is2005 = true;
3986
3987
break;
3987
3988
case TdsEnums.SQL2008_MAJOR << 24 | TdsEnums.SQL2008_MINOR:
3988
3989
if (increment != TdsEnums.SQL2008_INCREMENT)
3989
- {
3990
- throw SQL.InvalidTDSVersion();
3990
+ {
3991
+ throw SQL.InvalidTDSVersion();
3991
3992
}
3992
3993
_is2008 = true;
3993
3994
break;
3994
3995
case TdsEnums.SQL2012_MAJOR << 24 | TdsEnums.SQL2012_MINOR:
3995
3996
if (increment != TdsEnums.SQL2012_INCREMENT)
3996
- {
3997
- throw SQL.InvalidTDSVersion();
3997
+ {
3998
+ throw SQL.InvalidTDSVersion();
3998
3999
}
3999
4000
_is2012 = true;
4000
4001
break;
4001
4002
case TdsEnums.TDS8_MAJOR << 24 | TdsEnums.TDS8_MINOR:
4002
4003
if (increment != TdsEnums.TDS8_INCREMENT)
4003
- {
4004
- throw SQL.InvalidTDSVersion();
4004
+ {
4005
+ throw SQL.InvalidTDSVersion();
4005
4006
}
4006
4007
_is2022 = true;
4007
4008
break;
@@ -5934,7 +5935,7 @@ private TdsOperationStatus TryProcessColInfo(_SqlMetaDataSet columns, SqlDataRea
5934
5935
for (int i = 0; i < columns.Length; i++)
5935
5936
{
5936
5937
_SqlMetaData col = columns[i];
5937
-
5938
+
5938
5939
result = stateObj.TryReadByte(out _);
5939
5940
if (result != TdsOperationStatus.Done)
5940
5941
{
@@ -6471,7 +6472,7 @@ private TdsOperationStatus TryReadSqlStringValue(SqlBuffer value, byte type, int
6471
6472
char[] cc = null;
6472
6473
bool buffIsRented = false;
6473
6474
result = TryReadPlpUnicodeChars(ref cc, 0, length >> 1, stateObj, out length, supportRentedBuff: true, rentedBuff: ref buffIsRented);
6474
-
6475
+
6475
6476
if (result == TdsOperationStatus.Done)
6476
6477
{
6477
6478
if (length > 0)
@@ -11370,7 +11371,7 @@ internal object EncryptColumnValue(object value, SqlMetaDataPriv metadata, strin
11370
11371
actualLengthInBytes = (isSqlType) ? ((SqlBinary)value).Length : ((byte[])value).Length;
11371
11372
if (metadata.baseTI.length > 0 &&
11372
11373
actualLengthInBytes > metadata.baseTI.length)
11373
- {
11374
+ {
11374
11375
// see comments above
11375
11376
actualLengthInBytes = metadata.baseTI.length;
11376
11377
}
@@ -12278,7 +12279,7 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
12278
12279
_parser.WriteInt(count, _stateObj); // write length of chunk
12279
12280
task = _stateObj.WriteByteArray(buffer, count, offset, canAccumulate: false);
12280
12281
}
12281
-
12282
+
12282
12283
return task ?? Task.CompletedTask;
12283
12284
}
12284
12285
catch (System.OutOfMemoryException)
@@ -12511,7 +12512,7 @@ private async Task WriteTextFeed(TextDataFeed feed, Encoding encoding, bool need
12511
12512
char[] inBuff = ArrayPool<char>.Shared.Rent(constTextBufferSize);
12512
12513
12513
12514
encoding = encoding ?? new UnicodeEncoding(false, false);
12514
-
12515
+
12515
12516
using (ConstrainedTextWriter writer = new ConstrainedTextWriter(new StreamWriter(new TdsOutputStream(this, stateObj, null), encoding), size))
12516
12517
{
12517
12518
if (needBom)
@@ -13429,7 +13430,7 @@ internal TdsOperationStatus TryReadPlpUnicodeChars(
13429
13430
int charsRead = 0;
13430
13431
int charsLeft = 0;
13431
13432
char[] newbuf;
13432
-
13433
+
13433
13434
if (stateObj._longlen == 0)
13434
13435
{
13435
13436
Debug.Assert(stateObj._longlenleft == 0);
@@ -13546,7 +13547,7 @@ internal TdsOperationStatus TryReadPlpUnicodeChars(
13546
13547
totalCharsRead++;
13547
13548
}
13548
13549
if (stateObj._longlenleft == 0)
13549
- {
13550
+ {
13550
13551
// Read the next chunk or cleanup state if hit the end
13551
13552
result = stateObj.TryReadPlpLength(false, out _);
13552
13553
if (result != TdsOperationStatus.Done)
0 commit comments