Reputation: 27499
My problem is that when I get a SQL exception from the entity framework (say for example, because of a null value that isn't allowed to be null), it's sometimes hard to figure out which property is being referred to, and why it is null.
Now I know I can set up a SQL trace and log it which will give me the information I need, but this means I have to re-create the problem once I have turned logging on, which isn't always simple.
Ideally, I would like to be able to have the entity framework automatically include the actual SQL statement that caused the problem when it throws a SQL exception.
Is this possible?
Upvotes: 2
Views: 679
Reputation: 1008
Have you looked in the Errors property of the SqlException? It will contains a collection of SqlErrors that have the property Procedure that will state the name of the executed function that coused the error
Upvotes: 1
Reputation: 8913
if it is sql exception being thrown, then it will contain the detsil with it make sure that none of the exception is eaten away by throw new ex; or throw ex;, In catch use throw instead this will not suppress any part of the exception and you will have the detailed exception. this is the problem once I had hope it helps.
Upvotes: 0