开发者

Is it possible to have the entity framework include the SQL command when it throws exceptions?

开发者 https://www.devze.com 2022-12-18 06:36 出处:网络
My problem is that when I get a SQL exception from the entity framework (say for example, because of a nu开发者_如何学Goll value that isn\'t allowed to be null), it\'s sometimes hard to figure out whi

My problem is that when I get a SQL exception from the entity framework (say for example, because of a nu开发者_如何学Goll 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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消