Describe the bug
With SequentialAccess, calling GetFieldValueAsync<Stream> on its own returns a readable stream. If IsDBNullAsync is called first then the stream will have no data.
Using GetStream instead returns a readable stream in both cases.
To reproduce
Based on GetFieldValueAsync_OfStream unit test
using (SqlDataReader reader = await command.ExecuteReaderAsync(CommandBehavior.SequentialAccess))
{
if (await reader.ReadAsync() && !await reader.IsDBNullAsync(1))
{
using var buffer = new MemoryStream(originalData.Length);
// Doesn't have any bytes to read
using (Stream stream = await reader.GetFieldValueAsync<Stream>(1))
{
await stream.CopyToAsync(buffer);
outputData = buffer.ToArray();
}
// Works
//using (Stream stream = reader.GetStream(1))
//{
// await stream.CopyToAsync(buffer);
// outputData = buffer.ToArray();
//}
}
}
Debug.Assert(originalData.SequenceEqual(outputData));
Expected behavior
Expect GetFieldValueAsync<Stream> to work the same as GetStream in that IsDBNullAsync doesn't consume the column
Further technical details
Microsoft.Data.SqlClient version: 5.2.2
.NET target: .NET 8
SQL Server version: 2022
Operating system: Windows 11
Describe the bug
With SequentialAccess, calling
GetFieldValueAsync<Stream>on its own returns a readable stream. IfIsDBNullAsyncis called first then the stream will have no data.Using
GetStreaminstead returns a readable stream in both cases.To reproduce
Based on
GetFieldValueAsync_OfStreamunit testExpected behavior
Expect
GetFieldValueAsync<Stream>to work the same asGetStreamin thatIsDBNullAsyncdoesn't consume the columnFurther technical details
Microsoft.Data.SqlClient version: 5.2.2
.NET target: .NET 8
SQL Server version: 2022
Operating system: Windows 11