Use this stored procedure to process dbmlsync errors which are not categorized as database or communication errors. For example, you can implement the sp_hook_dbmlsync_misc_error hook to log errors or perform a specific action when a specific error occurs.
Name | Value | Description |
---|---|---|
publication_n (in) |
publication |
Deprecated. Use subscription_n instead. The publications being synchronized, where n is an integer. There is one publication_n entry for each publication being synchronized. The numbering of n starts at zero. |
MobiLink user (in) |
MobiLink user name |
The MobiLink user for which you are synchronizing. |
script version (in) |
script version name |
The MobiLink script version to be used for the synchronization. |
error message (in) | error message text | This is the same text that is displayed in the dbmlsync log. |
error id (in) | integer | An ID that uniquely identifies the message. Use this row to identify the error message, as the error message text may change. |
error hook user state (in|out) | integer |
This value can be set by the hook to pass state information to future calls to the sp_hook_dbmlsync_all_error, sp_hook_dbmlsync_communication_error, sp_hook_dbmlsync_misc_error, sp_hook_dbmlsync_sql_error, or sp_hook_dbmlsync_end hooks. The first time one of these hooks is called, the value of the row is 0. If a hook changes the value of the row, the new value is used in the next hook call. |
subscription_n (in) | subscription name(s) | The names of subscriptions being synchronized where n is an integer. This is one subscription_n entry for each subscription being synchronized. The numbering of n starts at zero. |
If an error occurs during startup before a synchronization has been initiated, the #hook_dict entries for MobiLink user and Script version are set to an empty string, and no publication_n or subscription_n rows are set in the #hook_dict table.
The error hook user state row provides a useful mechanism for you to pass information about the nature of the error to the sp_hook_dbmlsync_end hook where you might use that information to decide whether to retry the synchronization.
This procedure executes on a separate connection to ensure that operations it performs are not lost if a rollback is performed on the synchronization connection. If dbmlsync cannot establish a separate connection, the procedure is not called.
Since this hook executes on a separate connection you should use care when accessing tables that are being synchronized in your hook procedure because dbmlsync may have locks on these tables. These locks could cause operations in your hook to fail or to wait indefinitely.
Actions of this procedure are committed immediately after execution.
Assume you use the following table to log errors in the remote database.
CREATE TABLE error_log ( pk INTEGER DEFAULT AUTOINCREMENT PRIMARY KEY, err_id INTEGER, err_msg VARCHAR(10240), ); |
The following example sets up sp_hook_dbmlsync_misc_error to log all types of error messages.
CREATE PROCEDURE sp_hook_dbmlsync_misc_error() BEGIN DECLARE msg VARCHAR(10240); DECLARE id INTEGER; // get the error message text SELECT value INTO msg FROM #hook_dict WHERE name ='error message'; // get the error id SELECT value INTO id FROM #hook_dict WHERE name = 'error id'; // log the error information INSERT INTO error_log(err_msg,err_id) VALUES (msg,id); END; |
To see possible error id values, test run dbmlsync. For example, the following dbmlsync command line references an invalid subscription.
dbmlsync -c SERVER=custdb;UID=DBA;PWD=sql -s test |
Now, the error_log table contains the following row, associating the error with the error id 9931.
1,19912, 'Subscription ''test'' not found.' |
To provide custom error handling, check for the error id 19912 in sp_hook_dbmlsync_misc_error.
ALTER PROCEDURE sp_hook_dbmlsync_misc_error() BEGIN DECLARE msg VARCHAR(10240); DECLARE id INTEGER; // get the error message text SELECT value INTO msg FROM #hook_dict WHERE name ='error message'; // get the error id SELECT value INTO id FROM #hook_dict WHERE name = 'error id'; // log the error information INSERT INTO error_log(err_msg,err_id) VALUES (msg,id); IF id = 19912 THEN // handle invalid subscription END IF; END; |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |