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 Error Log Table.
Table: Error_Log
Columns:
3) Create trigger on Error Log table to set sequence to Log_ID on insert.
4) Create Error Log Procedure
5) Create Procedure which used Error Log Procedure in 3rd Step.
6) Execute Parent Procedure. Below is error output from Parent Procedure.
7) Check logs in Error Log table.
8) Create Config Table.
Table: Error_Log
Columns:
10) Create trigger on Config table to set sequence to Config_ID on insert.
11) Insert mail configuration data into Config Table.
13) Create function split
14) Create Procedure to send mails.
15) Create Procedure to send alert mails.
16) Create job to send error log alert daily once at 7:00 A.M.
17) Execute job to send alert mail. Below is alert mail.
Below are the scripts to download.
Note
We need to follow below steps.
1) Create Error Log Table.
Table: Error_Log
Columns:
- Log_ID
- Identity column.
- HOST_NAME
- Host Name.
- SERVICE_NAME
- Service Name.
- USER_NAME
- User Name.
- PROC_NAME
- Procedure Name.
- SQL_CODE
- Error Code from Procedure.
- SQL_ERRM
- Error Message from Procedure.
- ERROR_BACKTRACE
- Error Line Number from Procedure.
- Created_Date
- Default current date from database.
3) Create trigger on Error Log table to set sequence to Log_ID on insert.
4) Create Error Log Procedure
5) Create Procedure which used Error Log Procedure in 3rd Step.
6) Execute Parent Procedure. Below is error output from Parent Procedure.
7) Check logs in Error Log table.
8) Create Config Table.
Table: Error_Log
Columns:
- CONFIG_ID
- Identity column
- CONFIG_KEY
- Config Key
- CONFIG_VALUE
- Config Value
- IS_ACTIVE
- 1 = Config Key is active
- 0 = Config Key is inactive
- CREATED_DATE
- Default current date from database.
- MODIFIED_DATE
10) Create trigger on Config table to set sequence to Config_ID on insert.
11) Insert mail configuration data into Config Table.
- Mail_Smtp_Host
- Mail_From
- Mail_To
- Mail_Subject_Error_Log_Alert
13) Create function split
14) Create Procedure to send mails.
15) Create Procedure to send alert mails.
16) Create job to send error log alert daily once at 7:00 A.M.
17) Execute job to send alert mail. Below is alert mail.
Below are the scripts to download.
Note
- Before executing attached script replace your email id.
- You should have ACL created on your schema. (Check http://www.sqlscientist.com/2013/07/how-to-create-aclaccess-control-list-in.html)
No comments:
Post a Comment