Error Alert Script | Database Journal

Error Alert Script

Aug 30, 2002
2 minute read



To prevent databases from running into serious problems, DBAs typically setup alerts for specific errors; for example, the error “table corrupt” could lead to “database corrupted”. The problem is there are a large number of alerts for the “table corrupt” error message (about 40), and while you probably don’t want to set all 40 of the alerts on your server, you don’t want to miss any of them either. The solution is to simply set this alert job instead.

The job allows you to combine as many specific error messages as you want to monitor in just one single alert. For example, you can combine ” table corrupt” and ” DBCC” to monitor both by using this single job.

It applies to SQL Server 6.5/7.0/2000.


How the Job Works

Basically, the job will look up the SQL Server Error log files for specific error strings that the DBA wants to be notified of whenever they occur (for example : ” table corrupt” and “DBCC”) and then send an e-mail to the DBA composed of the error log lines that comprise the strings.

How to Create the Job


1. Create a text file comprised of the various strings you want to include (“Table corrupt”, for example). Name the file search.txt.

Note: for more information on how to create this file please refer to documentation for Window NT Findstr Utility or Microsoft SQL Server Administrator’s companion book.

2. Create a T-SQL job using this script:

exec xp_sendmail lname, fname

@subject = ' Search Errorlog'

@query = "declare @result varchar(125)

exec @result = xp_cmdshell ' findstr /i /g:c:mssql7logsearch.txt mssql7logerrorlog*.* ' "

Arguments:

c:mssql7logsearch.txt is the path of search.txt file

mssql7logerrorlog*.* is the path of the MS SQL Server error log file

Note: make sure that SQL Mail and SQL Server Agent are running; and that a valid MAPI Profile exists.

3. Schedule to run this job as a recurring job.


Stephanie Nguyen

Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.