Implementing error handling procedures

SQL Remote allows you to carry out some other process in addition to logging a message if an error occurs. The Replication_error database option allows you to specify a stored procedure to be called by the Message Agent when an error occurs. By default no procedure is called.

The procedure must have a single argument of type CHAR, VARCHAR, or LONG VARCHAR. The procedure is called twice: once with the error message and once with the SQL statement that causes the error.

While the option allows you to track and monitor errors in replication, you must still design them out of your setup: this option is not intended to resolve such errors.

For example, the procedure could insert the errors into a table with the current time and remote user ID, and this information can then replicate back to the consolidated database. An application at the consolidated database can create a report or send e-mail to an administrator when errors show up.

For information on setting the REPLICATION_ERROR option, see “SQL Remote options” on page 315 .

Example: e-mailing notification of errors

You may wish to receive some notification at the consolidated database when the Message Agent encounters errors. This section demonstrates a method to send Email messages to an administrator when an error occurs.

A stored procedure The stored procedure for this example is called sp_LogReplicationError, and is owned by the user cons. To cause this procedure to be called in the event of an error, set the Replication_error database option using Interactive SQL or Sybase Central:

SET OPTION PUBLIC.Replication_error = ’cons.sp_LogReplicationError’

The following stored procedure implements this notification:

CREATE PROCEDURE cons.sp_LogReplicationError (IN error_text LONG VARCHAR)

BEGIN

DECLARE current_remote_user CHAR(255);

SET current_remote_user = CURRENT REMOTE USER;

246

Page 264
Image 264
Sybase DC38133-01-0902-01 manual Implementing error handling procedures, Example e-mailing notification of errors, 246