How do you get full error information for a stored

2019-08-27 20:58发布

问题:

I am calling a stored procedure through LINQ-to-SQL (yes, I know it's deprecated). I am getting back an error, but the IExecuteResult only seems to be able to provide me with a number, when I would like the full string error description (like what you would get if you executed the SQL by hand in SQL Management Studio). Alternatively, is there somewhere I can find this information logged? I have looked through the Management/Log stuff in the database and it only seems to hold login and sync information.

Thanks!

回答1:

Some of these errors may have been logged into the SQL Server Log. For the rest, you might have to use the SQL Profiler and turn on one of the templates that displays errors and exceptions.

Alternatively, if you can reproduce the error, you could write some ADO.NET code to execute the same SP with the same parameters, then catch the SqlException that results. It will have all the error detail you could want, including a list of errors if there was more than one. You could also trap the information messages that may come back (PRINT statements, etc.)



回答2:

i was barking up the wrong tree. the SP wasn't returning anything :) thanks for the tip on the profiler though, I had never looked at that before!