Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error logging in SQL Server 2008

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.

like image 624
Manish Avatar asked Jan 16 '12 17:01

Manish


2 Answers

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

like image 84
hgulyan Avatar answered Oct 18 '22 00:10

hgulyan


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

like image 1
Siva Charan Avatar answered Oct 17 '22 23:10

Siva Charan