Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 17 » MobiLink - Server Administration » MobiLink events » Synchronization events

handle_odbc_error connection event

Executed whenever the MobiLink server encounters an ODBC error while invoking a data script.


In the following table, the description provides the SQL data type. If you are writing your script in Java or .NET, use the appropriate corresponding data type.

In SQL scripts, you can specify event parameters by name or with a question mark. Using question marks has been deprecated. Use named parameters instead. You cannot mix names and question marks within a script. If you use question marks, the parameters must be in the order shown below and are optional only if no subsequent parameters are specified (for example, you must use parameter 1 if you are going to use parameter 2). If you use named parameters, you can specify any subset of the parameters in any order.

Parameter name for SQL scripts Description Order (deprecated for SQL)
s.action_code INTEGER. This is an INOUT parameter. Set this value to tell the MobiLink server how to respond to the error. 1
s.odbc_state VARCHAR(5). The ODBC SQLSTATE. 2
s.error_message TEXT. The ODBC error message 3
s.remote_id VARCHAR(128). The MobiLink remote ID. You can only reference the remote ID if you are using named parameters. Not applicable
s.username VARCHAR(128). The MobiLink user name. 4
s.table VARCHAR(128). The table name. 5
s.script_version VARCHAR(128). Optional IN parameter to specify that the MobiLink server passes the script version string used for the current synchronization to this parameter. Question marks cannot be used to specify this parameter. Not applicable
Default action

The MobiLink server selects a default action. You can modify the action in the script, and return a value instructing MobiLink how to proceed. The action_code parameter takes one of the following values:

  • 1000

    Skip the current row and continue processing.

  • 3000

    Rollback the current transaction and cancel the current synchronization. This is the default action code, and is used when no handle_error script is defined or this script causes an error.

  • 4000

    Rollback the current transaction, cancel the synchronization, and shut down the MobiLink server.


The MobiLink server executes this script whenever it encounters an error flagged by the ODBC Driver Manager if the error occurs while MobiLink is processing an insert, update, or delete script during the upload transaction or is fetching download rows. If an ODBC error occurs at another time, the MobiLink server calls the report_error or report_odbc_error script and aborts the synchronization.

The error codes allow you to identify the nature of the error.

The action code tells the MobiLink server what to do next. Before it calls this script, the MobiLink server sets the action code to a default value, which depends on the severity of the error. Your script may modify this value. Your script must return or set an action code.

The handle_odbc_error script is called after the handle_error and report_error scripts, and before the report_odbc_error script.

When only one, but not both, error-handling script is defined, the return value from that script decides error behavior. When both error-handling scripts are defined, the MobiLink server uses the numerically highest action code. If both handle_error and handle_ODBC_error are defined, MobiLink uses the action code with the highest numerical value returned from all calls.

SQL example

The following example works with a SQL Anywhere consolidated database. It allows your application to ignore ODBC integrity constraint violations.

The following call to a MobiLink system procedure assigns the HandleODBCError stored procedure to the handle_odbc_error event.

CALL ml_add_connection_script(
 'CALL HandleODBCError( 
   {ml s.action_code}, 
   {ml s.ODBC_state}, 
   {ml s.error_message}, 
   {ml s.username}, 
   {ml s.table} )' )

The following SQL statement creates the HandleODBCError stored procedure.

   INOUT action integer,
   IN odbc_state varchar(5), 
   IN error_message varchar(1000),
   IN user_name varchar(128), 
   IN table_name varchar(128) )
   IF odbc_state = '23000' then
      -- Ignore the error and keep going.
      SET action = 1000;
      -- Abort the synchronization.
      SET action = 3000;
   END IF;
Java example

The following call to a MobiLink system procedure registers a Java method called handleODBCError as the script for the handle_odbc_error event when synchronizing the script version ver1.

CALL ml_add_java_connection_script(

The following is the sample Java method handleODBCError. It processes an error based on the data that is passed in. It also determines the resulting error code.

package ExamplePackage;
public class ExampleClass
    public void handleODBCError(	actionCode,
				 String					odbcState,
				 String					errorMessage,
				 String					user,
				 String					table ) 
	if( odbcState == "23000" ) {
	    // Ignore the error and keep going.
	    actionCode.setValue( 1000 );
	} else {
	    // Abort the synchronization.
	    actionCode.setValue( 3000 );
.NET example

The following call to a MobiLink system procedure registers a .NET method called HandleODBCError as the script for the handle_odbc_event when synchronizing the script version ver1.

CALL ml_add_dnet_connection_script(
 'TestScripts.Test.HandleODBCError' )

The following is the sample .NET method HandleODBCError.

namespace TestScripts
    public class Test
	public void HandleODBCError( ref int	actionCode,
				     string	odbcState,
				     string	errorMessage,
				     string	user,
				     string	table ) 
	    if( odbcState == "23000" ) {
		// Ignore the error and keep going.
		actionCode = 1000;
	    } else {
		// Abort the synchronization.
		actionCode = 3000;