Error Alert Script
December 6, 2002
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 composed of the error log lines that comprise the strings to the DBA.
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.
Author: Stephanie Nguyen
Disclaimer: We hope that the information on these script pages is
valuable to you. Your use of the information contained in these pages,
however, is at your sole risk. All information on these pages is provided
"as -is", without any warranty, whether express or implied, of its accuracy,
completeness, or fitness for a particular purpose...
Back to Database Journal Home