Search This Blog

Tuesday, December 16, 2008

Reading Sql Server and Sql Agent log files using T-SQL

xp_readerrrorlog

It is an undocumented extended stored procedure with at least 7 parameters (default null), that calls a dll to show results.

Parameters details as:

  1. Value of error log file you want to read: 0 = current, 1 = Archive #1, 2 = Archive #2, etc...
  2. Log file type: 1 or NULL = error log, 2 = SQL Agent log
  3. Search string 1: String one you want to search for
  4. Search string 2: String two you want to search for to further refine the results
  5. ? - Unknown
  6. ? - Unknown
  7. Sort order for results: N'asc' = ascending, N'desc' = descending

Example:
xp_readerrorlog 0, 2, 'ODBC', 'SQL Server',Null, Null , N'ASC'

LogDate                                   ErrorLevel     Text
2008-11-23 07:17:55.000   3                      [102] SQL Server ODBC driver version 9.00.3042

No comments: