Chapter 11. Administering SQL Remote for Adaptive Server

Anywhere

// Log the error

INSERT INTO cons.replication_audit ( remoteuser, errormsg)

VALUES

( current_remote_user, error_text);

COMMIT WORK;

//Now notify the DBA an error has occurred

//using email. We only want this information if

//the error occurred on the consolidated database

//We want the email to contain the error strings

//the Message Agent is passing to the procedure

IF CURRENT PUBLISHER = ’cons’ THEN

CALL sp_notify_DBA( error_text );

END IF

END;

The stored procedure calls another stored procedure to manage the sending of Email:

CREATE PROCEDURE sp_notify_DBA( in msg long varchar)

BEGIN

DECLARE rc INTEGER;

rc=call xp_startmail( mail_user=’davidf’ ); //If successful logon to mail

IF rc=0 THEN rc=call xp_sendmail(

recipient=’Doe, John; John, Elton’, subject=’SQL Remote Error’, "message"=msg);

//If mail sent successfully, stop IF rc=0 THEN

call xp_stopmail()

END IF END IF

END;

An audit table

An audit table could be defined as follows:

 

CREATE TABLE replication_audit (

 

id

INTEGER DEFAULT AUTOINCREMENT,

 

pub

CHAR(30) DEFAULT CURRENT PUBLISHER,

 

remoteuser CHAR(30),

 

errormsg

LONG VARCHAR,

 

timestamp

DATETIME DEFAULT CURRENT TIMESTAMP,

 

PRIMARY KEY (id,pub)

 

);

 

The columns have the following meaning:

247

Page 265
Image 265
Sybase DC38133-01-0902-01 manual Columns have the following meaning 247, Commit Work