I am executing a SQL insert statement e.g.
INSERT INTO Table (fk1, value1) OUTPUT inserted.pk VALUES ('fkv1', 'v1');
where "pk" is an auto incremented key value, as:
SqlDataReader reader = cmd.ExecuteReader();
The foreign key is in conflict with the parent table, and the reader.HasRows() reflects this, but how can I retrieve the actual exception object that was thrown with the error description? If you remove the "OUTPUT" statement, it throws the exception fine, but with that statement in there, it swallows the error, and just returns that "HasRows" == false.
I can see the error using the debugger under the "Results View" property, but how can I get this value in code?
Sql Server 2008r2 .NET 4.0
Thanks for any help.
EDIT:
This call does not throw an exception. The only indication that it has not completed successfully is that "HasRows" is false.
catch(ExceptionType ex), to get the exception's information.