One of the issue which we face while doing troubleshooting, is to read error logs of SQL server. one should have to go through GUI elements of SSMS to read the error logs . but it would be much more easier if one can read error logs through TSQL command as it provide more flexibility to filter out the information. xp_readerrrorlog is undocumented extended stored procedure which do just the same . it reads error log without going through GUI .
It takes four parameter to execute
- Parameter 1
Type :- INT
Name :- Error Log File
Default Value :- 0
Description :- 0 for current, 1 for Archive #1, 2 for Archive #2, and so on - Parameter 2
Type :- INT
Name :- Log File Type
Default Value :- 1
Description :- 1 for error log and 2 for SQL Server Agent log - Parameter 3
Type :- Varchar (255)
Name :- Search String 1
Description :- String one wants to search in error log - Parameter 2
Type :- varchar (255)
Name :- Search String 2
Description :- Its second string which can be searched to refine the search result
The above example search for “2005” and “exec” in current error log file for SQL server instance.