UltraLite C++ User's Guide
Tutorial: An Introductory 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
Add the method below to customer.cpp. This method carries out the following tasks:
Sets the synchronization stream to TCP/IP. Synchronization can also be carried out over HTTP, ActiveSync, or HTTPS. HTTPS synchronization requires that you obtain the separately licensable SQL Anywhere Studio security option.
MobiLink synchronization is controlled by scripts at the MobiLink synchronization server. The script version identifies which set of scripts to use. The setSendColumnNames method together with an option on the MobiLink synchronization server generates those scripts automatically.
For more information, see MobiLink Synchronization User's Guide.
Sets the MobiLink user ID. This is used for authentication at the MobiLink synchronization server, and is different from the UltraLite database user ID, although in some applications you may wish to make them the same.
Sets the synchronization to only download data. By default, MobiLink synchronization is two-way. Here, we use download-only synchronization so that the rows in your table do not get uploaded to the sample database.
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; }
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, as in Lesson 1: Connect to the database, but do not run the application yet.
To synchronize your data
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.
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 ...