Error logging in SQL Server 2008

12,521

Solution 1

Yes, you can.

Just implement try catch as it's described here TRY...CATCH . Error logging can be logged either in application or in sql by writing errors to a table.

If you want to log into a file, you can do that using SQLCLR. Check the answer here

How to log in T-SQL

There're some similar questions you can check.

Logging into table in SQL Server trigger

Best Practices - Stored Procedure Logging

Another approach is to use Log4Sql

Solution 2

View the SQL Server error log by using SQL Server Management Studio or any text editor.

By default, the error log is located at Program Files\Microsoft SQL Server\MSSQL.n\MSSQL\LOG\ERRORLOG and ERRORLOG.n files.

Go through Viewing the SQL Server Error Log page

Share:
12,521
Manish
Author by

Manish

Updated on July 27, 2022

Comments

  • Manish
    Manish almost 2 years

    A very short and straight question: I want to catch the error using try..catch and log it into a file. Is this possible in SQL Server 2008?

    Any directions, help are welcome.

  • hgulyan
    hgulyan over 12 years
    Why the downvote? The only answer, that brings an example of writing to a file using sqlclr.
  • Steam
    Steam about 10 years
    Msg 102, Level 15, State 1, Line 2 Incorrect syntax near 'Do'. Msg 102, Level 15, State 1, Line 8 Incorrect syntax near 'error_message'.
  • Oleg Dok
    Oleg Dok about 10 years
    @blasto Corrected, but it vas obvious. Isn't it?
  • lanartri
    lanartri about 9 years
    How is this going to work with a ROLLBACK in the Begin Catch ?