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

SQL Anywhere 12.0.0 (Français) » UltraLite - C and C++ Programming » API reference » Tutorial: Build an application using the C++ API


Lesson 4: Add synchronization to your application

This lesson synchronizes your application with a consolidated database running on your computer.

The following procedures add synchronization code to your application, start the MobiLink server, and run your application to synchronize.

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

This lesson assumes that you are familiar with MobiLink synchronization.

 ♦  To add synchronization to your application
  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. See UltraLite clients.

    • 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. Add the following line to the main method, immediately after the call to the insert method and before the call to the select method:

  3. Compile your application by running nmake.

 ♦  Synchronize data
  1. Start the MobiLink server.

    From a command prompt, run the following command:

    mlsrv12 -c "dsn=SQL Anywhere 12 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.

    For more information about this option, see MobiLink server options.

  2. Run your application by typing customer at the command prompt.

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