Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetFieldValueAsync<Stream> after IsDBNullAsync returns an empty stream #3057

Open
bbowyersmyth opened this issue Dec 3, 2024 · 1 comment
Assignees
Labels
✔️ Triage Done Issues that are triaged by dev team and are in investigation.

Comments

@bbowyersmyth
Copy link

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

@cheenamalhotra cheenamalhotra added the 🆕 Triage Needed For new issues, not triaged yet. label Dec 3, 2024
@bbowyersmyth
Copy link
Author

Was this by design at all @Wraith2 ?

@paulmedynski paulmedynski added ✔️ Triage Done Issues that are triaged by dev team and are in investigation. and removed 🆕 Triage Needed For new issues, not triaged yet. labels Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✔️ Triage Done Issues that are triaged by dev team and are in investigation.
Projects
None yet
Development

No branches or pull requests

3 participants