Skip to content

SqlClient: OUTPUT clause causes exceptions to not get thrown until read #80

@benrr101

Description

@benrr101

This scenario is a bit lengthy, so I'll load it into a gist: https://gist.github.com/benrr101/31628b57f1ab410090237c9018860e05

Basically what this boils down to is that if I .ExecuteReader() on a SqlCommand that has an OUTPUT clause in it, I don't get an exception from the query failing until I call .Read() on the SqlDataReader I gt back.

For instance executing:

INSERT INTO [dbo].[testtable]([small_col]) VALUES ("this value will be truncated")
SELECT * FROM [dbo].[testtable]
SqlDataReader reader = cmd.ExecuteReader(); // Doesn't throw
reader.Read() // DOES throw

But executing:

INSERT INTO [dbo].[testtable]([small_col]) OUTPUT inserted.[small_col] VALUES ("this value will be truncated")
SqlDataReader reader = cmd.ExecuteReader(); // DOES throw
reader.Read(); // Never executed

At this point I'm not sure if this is an expected behavior due to quirks in the TDS protocol or if it's a bug. Nevertheless, this is a bit of weird behavior that has already caused us a couple unexpected issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    By Design 🎨Issues due to driver feature design and will not be fixed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions