Monday, December 19, 2016

Reading SQL Server Error Log using XP_READERRORLOG

We use sp_readerrorlog for reading the content of the error log of SQL Server and it actually uses xp_readerrorlog extended stored procedure. Since I had to do some troubleshoot with one of servers, I use this for finding some info, and thought share it.

Here are some ways of reading the error log;




In case of you need the code;

  1. USE master;  
  2. GO  
  3.   
  4. -- without parameters, load the current log  
  5. EXEC xp_readerrorlog;  
  6.   
  7. -- Load the specific error log   
  8. -- 0 is current one and by default there are 6 more old logs  
  9. EXEC xp_readerrorlog 0;  
  10.   
  11. -- Second parameter is for log type  
  12. -- 1 is for engine and 2 is agent  
  13. EXEC xp_readerrorlog 0, 1;  
  14.   
  15. -- Two more additional parameters can be passed   
  16. -- for searching, 1st one is for searching  
  17. -- and second one for filter the search - or further searchin within the result  
  18. EXEC xp_readerrorlog 0, 1, N'Server', N'Listening';  
  19.   
  20. -- And this can take three more parameters  
  21. -- for setting the date range and sorting order  
  22. EXEC xp_readerrorlog 0, 1, N'Database', N'resource'  
  23.  , '2016-12-21 23:00:18.860''2016-12-21 23:00:18.930', N'DESC';  

No comments: