Reputation: 758
How does Error_Message()
function works and where is the raised error data stored?
I have to write some code to read all errors currently raised but not handled yet (CATCH
block is not reached end, in our DB it takes some minutes for a CATCH
block to finish). Now the question is:
Where can I get data related to raised errors?
Improve (UPDATE): suppose that I have a code like this:
BEGIN TRY
DECLARE @a INT = 1 / 0
END TRY
BEGIN CATCH
PRINT ERROR_MESSAGE()
-- What can I write instead of ERROR_MESSAGE() to get the same result?
END CATCH
Upvotes: 0
Views: 1025
Reputation: 2379
it is depend on Error Severity Level that you get in Error
Msg 547, Level 16
, State 0, Line 11
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Products_ Categories".
asp er my First point you can get Error at SQL Sever Log and Window Application Log
for SQL Server log
Object Explorer in the Management ➪ SQL Server Logs node lists the logs. Double-clicking a log opens SQL Server’s cool Log File Viewer
For Window Application Log
Control Panel ➪ System and Security ➪ Administrative Tools ➪ Event Viewer.
Upvotes: 1