@@ -323,9 +323,9 @@ internal virtual SmiExtendedMetaData[] GetInternalSmiMetaData()
323
323
collation != null ? collation . LCID : _defaultLCID ,
324
324
collation != null ? collation . SqlCompareOptions : SqlCompareOptions . None ,
325
325
colMetaData . udt ? . Type ,
326
- false , // isMultiValued
327
- null , // fieldmetadata
328
- null , // extended properties
326
+ isMultiValued : false ,
327
+ fieldMetaData : null ,
328
+ extendedProperties : null ,
329
329
colMetaData . column ,
330
330
typeSpecificNamePart1 ,
331
331
typeSpecificNamePart2 ,
@@ -443,7 +443,7 @@ internal void Bind(TdsParserStateObject stateObj)
443
443
_defaultLCID = _parser . DefaultLCID ;
444
444
}
445
445
446
- #if NET6_0_OR_GREATER
446
+ #if ! NETFRAMEWORK
447
447
[ SuppressMessage ( "ReflectionAnalysis" , "IL2111" ,
448
448
Justification = "System.Type.TypeInitializer would not be used in dataType and providerSpecificDataType columns." ) ]
449
449
#endif
@@ -763,11 +763,10 @@ private TdsOperationStatus TryCleanPartialRead()
763
763
{
764
764
AssertReaderState ( requireData : true , permitAsync : true ) ;
765
765
766
- TdsOperationStatus result ;
767
-
768
766
// VSTS DEVDIV2 380446: It is possible that read attempt we are cleaning after ended with partially
769
767
// processed header (if it falls between network packets). In this case the first thing to do is to
770
768
// finish reading the header, otherwise code will start treating unread header as TDS payload.
769
+ TdsOperationStatus result ;
771
770
if ( _stateObj . _partialHeaderBytesRead > 0 )
772
771
{
773
772
result = _stateObj . TryProcessHeader ( ) ;
@@ -1154,7 +1153,9 @@ private TdsOperationStatus TryConsumeMetaData()
1154
1153
// NOTE: We doom connection for TdsParserState.Closed since it indicates that it is in some abnormal and unstable state, probably as a result of
1155
1154
// closing from another thread. In general, TdsParserState.Closed does not necessitate dooming the connection.
1156
1155
if ( _parser . Connection != null )
1156
+ {
1157
1157
_parser . Connection . DoomThisConnection ( ) ;
1158
+ }
1158
1159
throw SQL . ConnectionDoomed ( ) ;
1159
1160
}
1160
1161
bool ignored ;
@@ -1252,7 +1253,7 @@ override public IEnumerator GetEnumerator()
1252
1253
}
1253
1254
1254
1255
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetFieldType/*' />
1255
- #if NET6_0_OR_GREATER
1256
+ #if ! NETFRAMEWORK
1256
1257
[ SuppressMessage ( "ReflectionAnalysis" , "IL2093:MismatchOnMethodReturnValueBetweenOverrides" ,
1257
1258
Justification = "Annotations for DbDataReader was not shipped in net6.0" ) ]
1258
1259
[ return : DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicProperties | DynamicallyAccessedMemberTypes . PublicFields ) ]
@@ -1273,7 +1274,7 @@ override public Type GetFieldType(int i)
1273
1274
}
1274
1275
}
1275
1276
1276
- #if NET6_0_OR_GREATER
1277
+ #if ! NETFRAMEWORK
1277
1278
[ return : DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicProperties | DynamicallyAccessedMemberTypes . PublicFields ) ]
1278
1279
#endif
1279
1280
private Type GetFieldTypeInternal ( _SqlMetaData metaData )
@@ -1368,7 +1369,7 @@ override public string GetName(int i)
1368
1369
}
1369
1370
1370
1371
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetProviderSpecificFieldType/*' />
1371
- #if NET8_0_OR_GREATER
1372
+ #if ! NETFRAMEWORK && NET8_0_OR_GREATER
1372
1373
[ return : DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicProperties | DynamicallyAccessedMemberTypes . PublicFields ) ]
1373
1374
#endif
1374
1375
override public Type GetProviderSpecificFieldType ( int i )
@@ -1387,7 +1388,7 @@ override public Type GetProviderSpecificFieldType(int i)
1387
1388
}
1388
1389
}
1389
1390
1390
- #if NET6_0_OR_GREATER
1391
+ #if ! NETFRAMEWORK
1391
1392
[ return : DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicProperties | DynamicallyAccessedMemberTypes . PublicFields ) ]
1392
1393
#endif
1393
1394
private Type GetProviderSpecificFieldTypeInternal ( _SqlMetaData metaData )
@@ -1712,7 +1713,9 @@ private TdsOperationStatus TryGetBytesInternal(int i, long dataIndex, byte[] buf
1712
1713
}
1713
1714
1714
1715
if ( dataIndex < 0 )
1716
+ {
1715
1717
throw ADP . NegativeParameter ( nameof ( dataIndex ) ) ;
1718
+ }
1716
1719
1717
1720
if ( dataIndex < _columnDataBytesRead )
1718
1721
{
@@ -1730,14 +1733,20 @@ private TdsOperationStatus TryGetBytesInternal(int i, long dataIndex, byte[] buf
1730
1733
1731
1734
// if bad buffer index, throw
1732
1735
if ( bufferIndex < 0 || bufferIndex >= buffer . Length )
1736
+ {
1733
1737
throw ADP . InvalidDestinationBufferIndex ( buffer . Length , bufferIndex , nameof ( bufferIndex ) ) ;
1738
+ }
1734
1739
1735
1740
// if there is not enough room in the buffer for data
1736
1741
if ( length + bufferIndex > buffer . Length )
1742
+ {
1737
1743
throw ADP . InvalidBufferSizeOrIndex ( length , bufferIndex ) ;
1744
+ }
1738
1745
1739
1746
if ( length < 0 )
1747
+ {
1740
1748
throw ADP . InvalidDataLength ( length ) ;
1749
+ }
1741
1750
1742
1751
// Skip if needed
1743
1752
if ( cb > 0 )
@@ -1774,7 +1783,9 @@ private TdsOperationStatus TryGetBytesInternal(int i, long dataIndex, byte[] buf
1774
1783
// note that since we are caching in an array, and arrays aren't 64 bit ready yet,
1775
1784
// we need can cast to int if the dataIndex is in range
1776
1785
if ( dataIndex < 0 )
1786
+ {
1777
1787
throw ADP . NegativeParameter ( nameof ( dataIndex ) ) ;
1788
+ }
1778
1789
1779
1790
if ( dataIndex > int . MaxValue )
1780
1791
{
@@ -1828,9 +1839,13 @@ private TdsOperationStatus TryGetBytesInternal(int i, long dataIndex, byte[] buf
1828
1839
{
1829
1840
// help the user out in the case where there's less data than requested
1830
1841
if ( ( ndataIndex + length ) > cbytes )
1842
+ {
1831
1843
cbytes = cbytes - ndataIndex ;
1844
+ }
1832
1845
else
1846
+ {
1833
1847
cbytes = length ;
1848
+ }
1834
1849
}
1835
1850
1836
1851
Buffer . BlockCopy ( data , ndataIndex , buffer , bufferIndex , cbytes ) ;
@@ -1844,15 +1859,21 @@ private TdsOperationStatus TryGetBytesInternal(int i, long dataIndex, byte[] buf
1844
1859
cbytes = data . Length ;
1845
1860
1846
1861
if ( length < 0 )
1862
+ {
1847
1863
throw ADP . InvalidDataLength ( length ) ;
1864
+ }
1848
1865
1849
1866
// if bad buffer index, throw
1850
1867
if ( bufferIndex < 0 || bufferIndex >= buffer . Length )
1868
+ {
1851
1869
throw ADP . InvalidDestinationBufferIndex ( buffer . Length , bufferIndex , nameof ( bufferIndex ) ) ;
1870
+ }
1852
1871
1853
1872
// if there is not enough room in the buffer for data
1854
1873
if ( cbytes + bufferIndex > buffer . Length )
1874
+ {
1855
1875
throw ADP . InvalidBufferSizeOrIndex ( cbytes , bufferIndex ) ;
1876
+ }
1856
1877
1857
1878
throw ;
1858
1879
}
@@ -1868,7 +1889,6 @@ internal int GetBytesInternalSequential(int i, byte[] buffer, int index, int len
1868
1889
throw ADP . AsyncOperationPending ( ) ;
1869
1890
}
1870
1891
1871
- TdsOperationStatus result ;
1872
1892
int value ;
1873
1893
SqlStatistics statistics = null ;
1874
1894
Debug . Assert ( _stateObj . _syncOverAsync , "Should not attempt pends in a synchronous call" ) ;
@@ -1877,7 +1897,7 @@ internal int GetBytesInternalSequential(int i, byte[] buffer, int index, int len
1877
1897
statistics = SqlStatistics . StartTimer ( Statistics ) ;
1878
1898
SetTimeout ( timeoutMilliseconds ?? _defaultTimeoutMilliseconds ) ;
1879
1899
1880
- result = TryReadColumnHeader ( i ) ;
1900
+ TdsOperationStatus result = TryReadColumnHeader ( i ) ;
1881
1901
if ( result != TdsOperationStatus . Done )
1882
1902
{
1883
1903
throw SQL . SynchronousCallMayNotPend ( ) ;
@@ -2161,17 +2181,23 @@ override public long GetChars(int i, long dataIndex, char[] buffer, int bufferIn
2161
2181
2162
2182
// if dataIndex outside of data range, return 0
2163
2183
if ( ndataIndex < 0 || ndataIndex >= cchars )
2184
+ {
2164
2185
return 0 ;
2186
+ }
2165
2187
2166
2188
try
2167
2189
{
2168
2190
if ( ndataIndex < cchars )
2169
2191
{
2170
2192
// help the user out in the case where there's less data than requested
2171
2193
if ( ( ndataIndex + length ) > cchars )
2194
+ {
2172
2195
cchars = cchars - ndataIndex ;
2196
+ }
2173
2197
else
2198
+ {
2174
2199
cchars = length ;
2200
+ }
2175
2201
}
2176
2202
2177
2203
Array . Copy ( _columnDataChars , ndataIndex , buffer , bufferIndex , cchars ) ;
@@ -2186,15 +2212,21 @@ override public long GetChars(int i, long dataIndex, char[] buffer, int bufferIn
2186
2212
cchars = _columnDataChars . Length ;
2187
2213
2188
2214
if ( length < 0 )
2215
+ {
2189
2216
throw ADP . InvalidDataLength ( length ) ;
2217
+ }
2190
2218
2191
2219
// if bad buffer index, throw
2192
2220
if ( bufferIndex < 0 || bufferIndex >= buffer . Length )
2221
+ {
2193
2222
throw ADP . InvalidDestinationBufferIndex ( buffer . Length , bufferIndex , nameof ( bufferIndex ) ) ;
2223
+ }
2194
2224
2195
2225
// if there is not enough room in the buffer for data
2196
2226
if ( cchars + bufferIndex > buffer . Length )
2227
+ {
2197
2228
throw ADP . InvalidBufferSizeOrIndex ( cchars , bufferIndex ) ;
2229
+ }
2198
2230
2199
2231
throw ;
2200
2232
}
@@ -2244,7 +2276,9 @@ private long GetCharsFromPlpData(int i, long dataIndex, char[] buffer, int buffe
2244
2276
// _columnDataCharsRead is 0 and dataIndex > _columnDataCharsRead is true below.
2245
2277
// In both cases we will clean decoder
2246
2278
if ( dataIndex == 0 )
2279
+ {
2247
2280
_stateObj . _plpdecoder = null ;
2281
+ }
2248
2282
2249
2283
bool isUnicode = _metaData [ i ] . metaType . IsNCharType ;
2250
2284
@@ -2617,7 +2651,7 @@ private object GetSqlValueFromSqlBufferInternal(SqlBuffer data, _SqlMetaData met
2617
2651
}
2618
2652
else
2619
2653
{
2620
- throw ADP . DataReaderClosed ( nameof ( GetSqlValueFromSqlBufferInternal ) ) ;
2654
+ throw ADP . DataReaderClosed ( ) ;
2621
2655
}
2622
2656
}
2623
2657
else
@@ -2817,7 +2851,7 @@ private object GetValueFromSqlBufferInternal(SqlBuffer data, _SqlMetaData metaDa
2817
2851
}
2818
2852
else
2819
2853
{
2820
- throw ADP . DataReaderClosed ( nameof ( GetValueFromSqlBufferInternal ) ) ;
2854
+ throw ADP . DataReaderClosed ( ) ;
2821
2855
}
2822
2856
}
2823
2857
}
@@ -2896,7 +2930,7 @@ private T GetFieldValueFromSqlBufferInternal<T>(SqlBuffer data, _SqlMetaData met
2896
2930
{
2897
2931
return ( T ) ( object ) data . DateTime ;
2898
2932
}
2899
- #if NET6_0_OR_GREATER
2933
+ #if ! NETFRAMEWORK
2900
2934
else if ( typeof ( T ) == typeof ( DateOnly ) && dataType == typeof ( DateTime ) && _typeSystem > SqlConnectionString . TypeSystem . SQLServer2005 )
2901
2935
{
2902
2936
return ( T ) ( object ) data . DateOnly ;
@@ -3557,7 +3591,7 @@ private TdsOperationStatus TryReadInternal(bool setTimeout, out bool more)
3557
3591
SqlStatistics statistics = null ;
3558
3592
using ( TryEventScope . Create ( "SqlDataReader.TryReadInternal | API | Object Id {0}" , ObjectID ) )
3559
3593
{
3560
- #if ! NET6_0_OR_GREATER
3594
+ #if NETFRAMEWORK
3561
3595
RuntimeHelpers . PrepareConstrainedRegions ( ) ;
3562
3596
#endif
3563
3597
@@ -3708,10 +3742,10 @@ private TdsOperationStatus TryReadInternal(bool setTimeout, out bool more)
3708
3742
if ( ( ! _sharedState . _dataReady ) && ( _stateObj . HasPendingData ) )
3709
3743
{
3710
3744
byte token ;
3711
- TdsOperationStatus debugResult = _stateObj . TryPeekByte ( out token ) ;
3712
- if ( debugResult != TdsOperationStatus . Done )
3745
+ result = _stateObj . TryPeekByte ( out token ) ;
3746
+ if ( result != TdsOperationStatus . Done )
3713
3747
{
3714
- return debugResult ;
3748
+ return result ;
3715
3749
}
3716
3750
3717
3751
Debug . Assert ( TdsParser . IsValidTdsToken ( token ) , $ "DataReady is false, but next token is invalid: { token , - 2 : X2} ") ;
@@ -3808,7 +3842,7 @@ private TdsOperationStatus TryReadColumnData()
3808
3842
3809
3843
TdsOperationStatus result = _parser . TryReadSqlValue ( _data [ _sharedState . _nextColumnDataToRead ] , columnMetaData , ( int ) _sharedState . _columnDataBytesRemaining , _stateObj ,
3810
3844
_command != null ? _command . ColumnEncryptionSetting : SqlCommandColumnEncryptionSetting . UseConnectionSetting ,
3811
- columnMetaData . column ) ;
3845
+ columnMetaData . column , _command ) ;
3812
3846
if ( result != TdsOperationStatus . Done )
3813
3847
{
3814
3848
// will read UDTs as VARBINARY.
@@ -3970,7 +4004,6 @@ internal TdsOperationStatus TryReadColumnInternal(int i, bool readHeaderOnly = f
3970
4004
}
3971
4005
else
3972
4006
{
3973
- // we have read past the column somehow, this is an error
3974
4007
Debug . Assert ( false , "We have read past the column somehow, this is an error" ) ;
3975
4008
}
3976
4009
}
@@ -4310,7 +4343,6 @@ internal TdsOperationStatus TrySetMetaData(_SqlMetaDataSet metaData, bool moreIn
4310
4343
4311
4344
if ( metaData != null )
4312
4345
{
4313
- TdsOperationStatus result ;
4314
4346
// we are done consuming metadata only if there is no moreInfo
4315
4347
if ( ! moreInfo )
4316
4348
{
@@ -4321,7 +4353,7 @@ internal TdsOperationStatus TrySetMetaData(_SqlMetaDataSet metaData, bool moreIn
4321
4353
// Peek, and if row token present, set _hasRows true since there is a
4322
4354
// row in the result
4323
4355
byte b ;
4324
- result = _stateObj . TryPeekByte ( out b ) ;
4356
+ TdsOperationStatus result = _stateObj . TryPeekByte ( out b ) ;
4325
4357
if ( result != TdsOperationStatus . Done )
4326
4358
{
4327
4359
return result ;
@@ -5201,7 +5233,7 @@ override public Task<T> GetFieldValueAsync<T>(int i, CancellationToken cancellat
5201
5233
var metaData = _metaData ;
5202
5234
if ( ( data != null ) && ( metaData != null ) )
5203
5235
{
5204
- return Task . FromResult < T > ( GetFieldValueFromSqlBufferInternal < T > ( data [ i ] , metaData [ i ] , isAsync : false ) ) ;
5236
+ return Task . FromResult < T > ( GetFieldValueFromSqlBufferInternal < T > ( data [ i ] , metaData [ i ] , isAsync : false ) ) ;
5205
5237
}
5206
5238
else
5207
5239
{
@@ -5241,7 +5273,7 @@ override public Task<T> GetFieldValueAsync<T>(int i, CancellationToken cancellat
5241
5273
{
5242
5274
_stateObj . _shouldHaveEnoughData = true ;
5243
5275
#endif
5244
- return Task . FromResult ( GetFieldValueInternal < T > ( i , isAsync : true ) ) ;
5276
+ return Task . FromResult ( GetFieldValueInternal < T > ( i , isAsync : true ) ) ;
5245
5277
#if DEBUG
5246
5278
}
5247
5279
finally
@@ -5305,19 +5337,24 @@ private static Task<T> GetFieldValueAsyncExecute<T>(Task task, object state)
5305
5337
reader . PrepareForAsyncContinuation ( ) ;
5306
5338
}
5307
5339
5308
- TdsOperationStatus result ;
5309
5340
if ( typeof ( T ) == typeof ( Stream ) || typeof ( T ) == typeof ( TextReader ) || typeof ( T ) == typeof ( XmlReader ) )
5310
5341
{
5311
- if ( reader . IsCommandBehavior ( CommandBehavior . SequentialAccess ) && reader . _sharedState . _dataReady && reader . TryReadColumnInternal ( context . _columnIndex , readHeaderOnly : true ) == TdsOperationStatus . Done )
5342
+ if ( reader . IsCommandBehavior ( CommandBehavior . SequentialAccess ) && reader . _sharedState . _dataReady )
5312
5343
{
5313
- return Task . FromResult < T > ( reader . GetFieldValueFromSqlBufferInternal < T > ( reader . _data [ columnIndex ] , reader . _metaData [ columnIndex ] , isAsync : true ) ) ;
5344
+ bool internalReadSuccess = false ;
5345
+ internalReadSuccess = reader . TryReadColumnInternal ( context . _columnIndex , readHeaderOnly : true ) == TdsOperationStatus . Done ;
5346
+
5347
+ if ( internalReadSuccess )
5348
+ {
5349
+ return Task . FromResult < T > ( reader . GetFieldValueFromSqlBufferInternal < T > ( reader . _data [ columnIndex ] , reader . _metaData [ columnIndex ] , isAsync : true ) ) ;
5350
+ }
5314
5351
}
5315
5352
}
5316
5353
5317
- result = reader . TryReadColumn ( columnIndex , setTimeout : false ) ;
5354
+ TdsOperationStatus result = reader . TryReadColumn ( columnIndex , setTimeout : false ) ;
5318
5355
if ( result == TdsOperationStatus . Done )
5319
5356
{
5320
- return Task . FromResult < T > ( reader . GetFieldValueFromSqlBufferInternal < T > ( reader . _data [ columnIndex ] , reader . _metaData [ columnIndex ] , isAsync : false ) ) ;
5357
+ return Task . FromResult < T > ( reader . GetFieldValueFromSqlBufferInternal < T > ( reader . _data [ columnIndex ] , reader . _metaData [ columnIndex ] , isAsync : false ) ) ;
5321
5358
}
5322
5359
else
5323
5360
{
@@ -5683,7 +5720,7 @@ private void CompleteAsyncCall<T>(Task<T> task, SqlDataReaderBaseAsyncCallContex
5683
5720
}
5684
5721
5685
5722
5686
- internal class Snapshot
5723
+ internal sealed class Snapshot
5687
5724
{
5688
5725
public bool _dataReady ;
5689
5726
public bool _haltRead ;
0 commit comments