Contents Index Lesson 3: Select the rows from the table Understanding UltraLite Development

UltraLite C++ User's Guide
  Tutorial: An Introductory Application

Lesson 4: Add synchronization to your application


This lesson provides instructions to add synchronization code to your application, start the MobiLink synchronization server, and run your application to synchronize.

This lesson uses MobiLink synchronization, which is part of SQL Anywhere Studio. You must have the SQL Anywhere Studio installed to carry out this lesson.

The application synchronizes your database with ASA 9.0 Sample database. The ASA 9.0 sample database has a ULCustomer table that matches the columns in your UltraLite databse. Thus, you can synchronize your application with this databse.

This lesson assumes familiarity with MobiLink synchronization.

To add synchronization to your application

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

    bool do_sync( Connection * conn ) {
      ul_synch_info    info;
      conn->InitSynchInfo( &info );
      info.stream = ULSocketStream();
      info.version = UL_TEXT( "ul_default" );
      info.user_name = UL_TEXT( "sample" );
      info.send_column_names = true;
      info.download_only = true;
      if( !conn->Synchronize( &info ) ) {
          handle_error( _TEXT("synchronize") );
          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:

    do_sync(conn);
  3. Compile your application, as in Lesson 1: Connect to the database, but do not run the application yet.

To synchronize your data

  1. Start the MobiLink synchronization server.

    From a command prompt, run the following command:

    dbmlsrv9 -c "dsn=ASA 9.0 Sample" -v+ -zu+ -za

    The -zu+ and -za command line options provide automatic addition of users and generation of synchronization scripts. For more information on these options, see the MobiLink Synchronization User's Guide.

  2. Run your application, as in Lesson 1: Connect to the database

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

    The data downloaded from the sample database are listed at the command prompt window, confirming that the synchronization succeeded.

    Connected to an existing database.
    The table has 128 rows.
    id= 1, name= Gene Poole
    id= 2, name= Penny Stamp
    id= 101, name= Michaels Devlin
    id= 102, name= Beth Reiser
    id= 103, name= Erin Niedringhaus
    id= 104, name= Meghan Mason
    ...

Contents Index Lesson 3: Select the rows from the table Understanding UltraLite Development