A Quick and Easy Way to View Errorlog Files

Downloads
95134.zip

I created a stored procedure, sp_ShowErrors, to view SQL Server errorlog files. In its default configuration, this stored procedure takes the two most recent errorlog files and produces a report that highlights errorlog entries of interest. To give context to those errorlog entries, the report also includes (but doesn't highlight) the preceding and following four entries in the errorlog file.

This stored procedure has saved me countless hours of tedium over the years. For example, by adding sp_ShowErrors to a batch process that runs on more than 40 servers and concatenating the results to one file, I can review the errorlog files for all the servers in a matter of minutes. It's a great alternative to logging on to each server and manually reviewing the errorlog files through the GUI or not even reviewing them at all due to time constraints. I have performance-tuned sp_ShowErrors so that it can handle even the largest errorlog file that would cause Enterprise Manager to choke.

Listing 1 shows an excerpt from sp_ShowErrors. (You can download the entire stored procedure from the SQL Server Web site.) As callout A shows, sp_ShowErrors uses the sp_readerrorlog stored procedure. Note that sp_readerrorlog is undocumented, so you need to use at your own risk.

I wrote sp_ShowErrors for SQL Server 2000. To get it working in SQL Server 2005, you'll need to modify the code because the output of sp_readerrorlog in SQL Server 2005 is different. I hope you find this stored procedure as useful as I do.
—Bill McEvoy

Discuss this Article 3

Alexander (not verified)
on Oct 5, 2007
Great, it's working!
Brandie (not verified)
on Aug 12, 2008
great script
Yannick (not verified)
on May 31, 2007
great stuff

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Michael Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 21, 2013
blog

A Common Misconception about MAXDOP

Out of the box, SQL Server is (and has been) able to take advantage of multiple processors/cores without any effort on behalf of administrators....More
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.