I’ve got a logger that records exception information for our in house applications.
When we log SQL exceptions it’d be super useful if we could see the actual query that caused the exception.
Is there a way we can achieve this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
SqlExceptiondoes not hold a reference to theSqlCommandthat caused the exception. In your logger there is no way to do this. What you could do is catch the SqlException in the method that executes theSqlCommandand wrap it in a more descriptive exception. Example:This way you can log this more expressive exception.