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

SAP Sybase SQL Anywhere 16.0 » UltraLite - C and C++ Programming » Tutorial: Building a Windows application using the C++ API


Lesson 4: Adding synchronization to your application

In this lesson, you add synchronization code to your application, start the MobiLink server, and run your application to synchronize with the consolidated database.


This lesson assumes you have completed all preceding lessons. See Lesson 1: Creating and connecting to a database.

Contexte et remarques

The UltraLite database you created in the previous lessons synchronizes with the UltraLite 16 Sample database. The UltraLite 16 Sample database has a ULCustomer table whose columns include those in the customer table of your local UltraLite database.

  1. Add the method below to customer.cpp. This method carries out the following tasks:

    • Enables TCP/IP communications by invoking EnableTcpipSynchronization. Synchronization can also be carried out over HTTP, HTTPS, and TLS.

    • Sets the script version. MobiLink synchronization is controlled by scripts stored in the consolidated database. The script version identifies which set of scripts to use.

    • Sets the MobiLink user name. This value is used for authentication at the MobiLink server. It is distinct from the UltraLite database user ID, although in some applications you may want to give them the same value.

    • Sets the download_only parameter to true. By default, MobiLink synchronization is two-way. This application uses download-only synchronization so that the rows in your table do not get uploaded to the sample database.

    static bool do_sync( ULConnection * conn )
        ul_sync_info info;
        ul_stream_error * se = &info.stream_error;
        conn->InitSyncInfo( &info ); = "TCPIP";
        info.version = "custdb 12.0";
        info.user_name = "50";
        info.download_only = true;
        if( !conn->Synchronize( &info ) ) {
            _tprintf( "Synchronization error \n" );   
            _tprintf( "  stream_error_code is '%lu'\n", se->stream_error_code );
            _tprintf( "  system_error_code is '%ld'\n", se->system_error_code );
            _tprintf( "  error_string is '" );
            _tprintf( "%s", se->error_string );
            _tprintf( "'\n" );
            return false;
        return true;
  2. Place the following line of code to the main method after the do_select method call:

  3. Compile your application by running nmake.

  4. Start the MobiLink server.

    At a command prompt, run the following command:

    mlsrv16 -c "dsn=SQL Anywhere 16 CustDB;uid=ml_server;pwd=sql" -v -vr -vs -zu+ -o custdbASA.log

    The -zu+ option provides automatic addition of users. The -v+ option turns on verbose logging for all messages.

  5. Run your application by typing customer at a command prompt.


The MobiLink server messages window displays status messages indicating the synchronization progress. If synchronization is successful, the final message displays Synchronization complete.

 See also