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.
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; ULDatabaseManager::EnableTcpipSynchronization(); conn->InitSyncInfo( &info ); info.stream = "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; } |
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); |
Compile your application by running nmake.
Start the MobiLink server.
At 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.
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
.
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |