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

SQL Anywhere 10.0.1 » UltraLite - C and C++ Programming » Tutorial: Build an Application Using the C++ API

Lesson 3: Select and list rows from the table Next Page

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 10.0 Sample database. The UltraLite 10.0 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.

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;
      ul_stream_error * se = &info.stream_error;
      
      ULEnableTcpipSynchronization( Tutca.GetCA() );
      conn->InitSynchInfo( &info );
      info.stream = ULSocketStream();
      info.version = UL_TEXT( "custdb 10.0" );
      info.user_name = UL_TEXT( "50" );
      info.download_only = true;
      if( !conn->Synchronize( &info ) ) {
          _tprintf( _TEXT("Synchronization error \n" ));   
       _tprintf( _TEXT("  stream_error_code is '%lu'\n"), se->stream_error_code );
       _tprintf( _TEXT("  system_error_code is '%ld'\n"), se->system_error_code );
       _tprintf( _TEXT("  error_string is '") );
       _tprintf( _TEXT("%s"), se->error_string );
       _tprintf( _TEXT("'\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:

    do_sync(conn);
  3. Compile your application by running nmake.

Synchronize data
  1. Start the MobiLink server.

    From a command prompt, run the following command:

    mlsrv10 -c "dsn=SQL Anywhere 10 CustDB" -v+ -zu+

    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 window displays status messages indicating the synchronization progress. If synchronization is successful, the final message displays Synchronization complete.