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

SQL Anywhere 10.0.1 » MobiLink - Server Administration » Synchronization Events

handle_error connection event Next Page

handle_odbc_error connection event

Executed whenever the MobiLink server encounters an error triggered by the ODBC Driver Manager.


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

In SQL scripts, you can specify event parameters by name or with a question mark, but 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 want 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




INTEGER. This is an INOUT parameter.








s.remote_id VARCHAR(128). The MobiLink remote ID. You can only reference the remote ID if you are using named parameters.Not applicable


VARCHAR(128). The MobiLink user name.





Default action

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


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 upon 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.

See also
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(

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.

public String handleODBCError( actionCode,
  String ODBCState,
  String errorMessage,
  String user,
  String table ) {
  int new_ac;
  if( user == null ) {
    new_ac = handleNonSyncError( ODBCState,
  errorMessage ); 

  else if( table == null ) {
    new_ac = handleConnectionError( ODBCState,
     errorMessage, user ); 
  } else {  
    new_ac = handleTableError( ODBCState,
     errorMessage, user, table ); 
  // Keep the most serious action code.
  if( actionCode.getValue() < new_ac ) {
    actionCode.setValue( new_ac ); 
  return( null ); 
.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' )

Following is the sample .NET method HandleODBCError.

public string HandleODBCError (
  ref int actionCode,
  string ODBCState,
  string errorMessage,
  string user,
  string table ) {
  int new_ac;
  if( user == null ) {
    new_ac = HandleNonSyncError( ODBCState,
      errorMessage ); 
  else if( table == null ) {
    new_ac = HandleConnectionError( ODBCState,
     errorMessage, user ); 
  } else {  
    new_ac = HandleTableError( ODBCState,
     errorMessage, user, table ); 
  // Keep the most serious action code.
  if( actionCode < new_ac ) {
    actionCode = new_ac; 
  return( null );