question

jctronicsshiva avatar image
jctronicsshiva asked

How to write errorlog to the SQL errorlog file from stored proc

Suppose i am executing a stored proc . Lets there is an exception, how do i write the log in errorlog of MSSQL? I read about RAISERROR, i got to know that it basically throw exception message to the batch or application? can someone provide me some links to read about it. Suppose if the stored procedure returns int after executing , will it still return the value in case raiserror is called?
sql-server-2005t-sqlstored-proceduresdatabase
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Grant Fritchey avatar image
Grant Fritchey answered
You can just specify [LOG as part of the RAISERROR][1] command. You can see the details in the Books Online. For more detail around how to deal with errors in SQL Server, [I have an older article][2] that works all around errors and error handling. It was written for SQL Server 2005, but it's still mostly applicable to 2008R2 and 2012. [1]: http://msdn.microsoft.com/en-us/library/ms178592(v=sql.90).aspx [2]: https://www.simple-talk.com/sql/t-sql-programming/sql-server-error-handling-workbench/
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.