Introducing SQL Anywhere Studio
Tutorial: Synchronizing Databases with MobiLink
Synchronization is governed by the following:
Synchronization publications, users, and subscriptions These are defined in each remote database.
Synchronization scripts These are written in SQL and held in the consolidated database. Alternatively, you can write synchronization scripts in Java and store them in a location accessible by the MobiLink synchronization server. In this tutorial we use SQL scripts.
You can write, view and modify synchronization scripts as well as publications and subscriptions using Sybase Central.
The MobiLink synchronization publication, user, and subscription are necessary for MobiLink synchronization to happen. Each is defined in the remote database.
To add a publication and synchronization subscription to the remote database
Start Sybase Central and connect to your remote database:
From the Start Button, click Programs
Right-click Adaptive Server Anywhere 9 and choose Connect from the popup menu.
Enter an ODBC data source name of test_remote and click OK to connect.
Add a publication to the remote database:
In Sybase Central, open the remote database.
Open the Publications folder.
From the File menu, choose New
Name the publication Customer and click Next.
Double-click the table cust to add it to the list of selected tables and click Finish to create the publication.
Add a MobiLink user name to the remote database:
In Sybase Central, open the remote database.
Open the MobiLink Users folder.
From the File menu, choose New
Name the user ml_user and click Finish to create the user.
Subscribe the MobiLink user to the publication:
In the left pane, open the Publications folder so that the Customer publication is visible.
In the right pane, click the ml_user MobiLink user.
Drag the MobiLink user onto the Customer publication.
You are asked whether to subscribe the user to the publication. Click Yes.
Add address information to the subscription:
Address information is used to enable the MobiLink client to locate the correct MobiLink synchronization server.
Right click the MobiLink user ml_user, and choose Properties from the popup menu.
On the Connection tab, enter the following information, leaving the other fields blank:
Host localhost.
If the MobiLink synchronization server were running on a different machine, you would enter the machine name or IP number instead of localhost.
Click OK to add the address information.
This completes the preparation of the remote database. The next step is to add synchronization scripts for the consolidated database.
Each script belongs to a designated script version. You must add a script version to the consolidated database before you add scripts.
To add a script version
Start Sybase Central and connect to the test_consol data source using the MobiLink plug-in.
Open the Versions folder.
Double click Add Version. Name the new version default.
To add synchronized tables to your consolidated database
Open the Tables folder beneath the MobiLink Synchronization9 icon.
Open the DBA container. Right-click the cust table and add it to synchronized tables.
Now that you have designated these tables as tables to be synchronized, you can add a new table script for each upload and download to the consolidated database.
To add table scripts to each synchronized table
Open the Synchronized Tables folder, and double-click the cust table.
Double click Add Table Script in the right pane. The Add Synchronizing Table Script wizard appears.
Select the upload_insert event from the drop list.
Click Finish.
Type the following code into the dialog:
INSERT INTO cust ( cust_id, emp_id, cust_name ) VALUES ( ?, ?, ? )
Save the script and close the dialog.
Repeat this step for the download_cursor event, using the following script:
SELECT cust_id, emp_id, cust_name FROM cust
You have now generated scripts that perform a snapshot synchronization of your database, uploading new rows to the consolidated database and downloading rows from the consolidated database to the remote. In a complete MobiLink installation, you would add scripts for other events.