Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin.
Search for scripts directly from SSMS, and instantly access any saved scripts in your
SSC briefcase from the favorites tab.
Download now (direct download link)
Thank this author by sharing:
By Alejandro Pelc,
This stored procedure is based on the native SQL sp sp_readerrorlog, but with the addition of selecting all error logs for searching string patterns. It also has the flexibility of knowing the amount of error log files configured, so in case you specify an invalid number, the sp will let you know the valid numbers.
The script is executed with the following parameters:
The @AllLogs parameter is used to determine if the search will be performed on all error log files. In case its value is 0, then the parameter @LogFile is used to know on which error log file to search. If @AllLogs is 0, then @LogFile cannot be null. If is 1, then @LogFile is ignored.
Finally, there are two parameters (@SearchString1 and @SearchString2) that represent the strings to look for. If no value is specified, all records will be returned.
Assuming you have SQL Server configured with the default quantity of error log files (6) and you perform the following query, exec sp_SearchSQLErrorLog @AllLogs = 0, @LogFile = 6, @SearchString1 = 'login', @SearchString2 = 'sa', then you'll get all records from the sixth log file containing the words login and sa.
If you run the same query but changing the @LogFile parameter to 7, then you'll receive a message error like the following:
Msg 50000, Level 11, State 3, Procedure sp_SearchSQLErrorLog, Line 63You must specify a valid log file. The logfile 7 is invalid. Valid values are 1 to 6
SYNTAX ERROR USING PARAMETERS
backup log no longer exist in SQL 2008 (shrink logfile)
Creating a report with two datasets that reference the same pair of parameters, I’m seeing the follo...
truncate the transactional logfile
TSQL error: 'Invalid length parameter passed to the substring function.'