Error Logging is main part of our database application. I am trying to share some sample code which I am using in my daily life.
We need to follow below steps.
1) Create database.
2) Create Error Log Table.
Table: Error_Log
Columns:
4) Create Procedure with error which used Error Log Procedure in 3rd Step.
5) Execute Parent Procedure. Below is error output from Parent Procedure.
66) Check logs in Error Log table.
![image image](http://lh6.ggpht.com/--8FWLCjMq9Q/UdKMTUheeEI/AAAAAAAAApU/ELMIvBcvolk/image_thumb7.png?imgmax=800)
7) Create Config Table. Add below entry for Mail Configuration.
9) Create Job to execute Procedure to send alert mails. Below is alert mail.
![image image](http://lh4.ggpht.com/-xKeUIFRMMjI/UdKMU2vuFhI/AAAAAAAAApk/_PZ1YADPbao/image_thumb%25255B3%25255D.png?imgmax=800)
Below are the scripts to download.
Error Logging and Alerts.sql
We need to follow below steps.
1) Create database.
2) Create Error Log Table.
Table: Error_Log
Columns:
- Log_ID
- Identity column.
- Database_Name
- Database Name.
- Proc_Name
- Procedure Name.
- Err_Number
- Error Number from Procedure.
- Err_State
- Error Stage from Procedure.
- Err_Message
- Error Message from Procedure.
- Err_Line
- Error Line from Procedure.
- Created_Date
- Default current date from database.
4) Create Procedure with error which used Error Log Procedure in 3rd Step.
5) Execute Parent Procedure. Below is error output from Parent Procedure.
![image image](http://lh6.ggpht.com/--rEK6DYd4qg/UdKMRpM19FI/AAAAAAAAApE/v_HmOIFPf4w/image_thumb1.png?imgmax=800)
![image image](http://lh6.ggpht.com/--8FWLCjMq9Q/UdKMTUheeEI/AAAAAAAAApU/ELMIvBcvolk/image_thumb7.png?imgmax=800)
7) Create Config Table. Add below entry for Mail Configuration.
- Mail_From
- Mail_Subject_Error_Log_Alert
- Mail_To
9) Create Job to execute Procedure to send alert mails. Below is alert mail.
![image image](http://lh4.ggpht.com/-xKeUIFRMMjI/UdKMU2vuFhI/AAAAAAAAApk/_PZ1YADPbao/image_thumb%25255B3%25255D.png?imgmax=800)
Below are the scripts to download.
Error Logging and Alerts.sql
No comments:
Post a Comment