Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Tips Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS Access
SQL Scripts & Samples
» Database Forum
» Slideshows
Free Newsletters:

News Via RSS Feed

Database Journal |DBA Support |SQLCourse |SQLCourse2

Featured Database Articles

SQL Scripts & Samples

Posted Aug 30, 2002

Error Alert Script

By DatabaseJournal.com Staff

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:\mssql7\log\search.txt \mssql7\log\errorlog*.* ' "


- c:\mssql7\log\search.txt is the path of search.txt file
- \mssql7\log\errorlog*.* 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

SQL Scripts & Samples Archives

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Latest Forum Threads
SQL Scripts & Samples Forum
Topic By Replies Updated
sql help!! add 1 August 22nd, 11:58 AM
How To Combine These 2 Queries into 1 Query ? tarek_land 1 June 7th, 08:37 AM
solving query svibuk 1 February 3rd, 06:08 AM
converting from a character string to uniqueidentifier saturnius 4 January 4th, 05:56 AM