Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

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)

Search SQL Error Log

By Alejandro Pelc,

Description

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:

  • @AllLogs
  • @LogFile
  • @SearchString1
  • @SearchString2

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.

Examples

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 63
You must specify a valid log file. The logfile 7 is invalid. Valid values are 1 to 6

 

Total article views: 1893 | Views in the last 30 days: 5
 
Related Articles
FORUM

shrinking logfile in SQL 2008

backup log no longer exist in SQL 2008 (shrink logfile)

FORUM

SYNTAX ERROR USING PARAMETERS

SYNTAX ERROR USING PARAMETERS

BLOG

Debugging Parameter Dependencies in Reporting Services

Creating a report with two datasets that reference the same pair of parameters, I’m seeing the follo...

FORUM

truncate the transactional logfile

truncate the transactional logfile

FORUM

TSQL error: 'Invalid length parameter passed to the substring function.'

TSQL error: 'Invalid length parameter passed to the substring function.'

Tags
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones