About MobiLink synchronization

MobiLink is a session-based synchronization system that allows one- or two-way synchronization between a central data source, typically a consolidated database, and many remote databases. Administration and resource requirements at the remote database sites are minimal, making MobiLink well suited to a variety of mobile applications.

NoteWhere to find additional information Detailed information about MobiLink synchronization is provided in the MobiLink Getting Started, the MobiLink - Client Administration, and the Mobilink - Server Administration books. These books are available online on the SQL Anywhere Product Manuals Web site.

If you are already familiar with MobiLink, go to “Working with PocketBuilder synchronization objects” to learn about PocketBuilder integration with MobiLink.

This section introduces some MobiLink terms and concepts.

Data movement and synchronization

Data movement occurs when shared data is distributed over multiple databases on multiple nodes and changes to data in one database are applied to the corresponding data in other databases. Data can be moved using replication or synchronization.

Data replication moves all transactions from one database to another, whereas data synchronization moves only the net result of transactions. Both techniques get their information by scanning transaction log files, but synchronization uses log file segments instead of the full log file, making data movement much faster and more efficient.

With synchronization, data is available locally and can be modified without a connection to a server. MobiLink synchronization uses a loose consistency model, which means that all changes are synchronized with each site over time in a consistent manner, but different sites might have different copies of data at any instant. Only successful transactions are synchronized.

Consolidated and remote databases

The consolidated database, which can be any ODBC-compliant database, such as SQL Anywhere, Adaptive Server Enterprise, Oracle, IBM DB2 UDB, or Microsoft SQL Server, holds the master copy of all the data. Optionally, in MobiLink 10, you can store all or part of your central data in a data source such as an application server, spreadsheet, Web server, Web service, or text file.

For information on using a central data source other than a consolidated database, see the chapter on direct row handling in the MobiLink Server Administration book.

The remote database contains a subset of the consolidated data. In PocketBuilder, the remote database is a SQL Anywhere or UltraLite database.

The MobiLink synchronization server

The MobiLink synchronization server, dbmlsrv9 or mlsrv10, manages the synchronization process and provides the interface between remote databases and the consolidated database server. All communication between the MobiLink synchronization server and the consolidated database occurs through an ODBC connection.The consolidated database and synchronization server often reside on the same machine, but that is not a requirement.

The MobiLink server must be running before a synchronization process is launched.

As you build and test PocketBuilder applications, you can start the server from the Utilities folder in the Objects view in the Database painter. For more information, see the chapter on managing databases in the PocketBuilder User’s Guide.

For information about starting the server from the command line, see “mlsrv10” in the index of the SQL Anywhere Studio online books.

MobiLink hierarchy

MobiLink typically uses a hierarchical configuration. The nodes in the hierarchy can reside on servers, desktop computers, and handheld or embedded devices. A simple hierarchy might consist of a consolidated database on a server and multiple remote databases on mobile devices. A more complex hierarchy might contain multiple levels in which some sites act as both remote and consolidated databases. Any consolidated database that also acts as a remote database must be a SQL Anywhere database.

For example, suppose remote sites A1, A2, and A3 synchronize with a consolidated database A on a local server, and remote sites B1, B2, and B3 synchronize with a consolidated database B on another local server. A and B in turn act as remote sites and synchronize with a consolidated database C on a master server. C can be any ODBC-compliant database, but A and B must both be SQL Anywhere databases.

Figure 17-1: MobiLink hierarchy

The consolidated database is shown at the top with MobiLink connections to intermediate layer dabases that serve both as remote databases to the top-level consolidated database and as a consolidated database for lower level remote databases.

Synchronization scripts

MobiLink synchronization is an event-driven process. When a MobiLink client initiates a synchronization, a number of synchronization events occur inside the MobiLink server. When an event occurs, MobiLink looks for a script to match the synchronization event. If you want the MobiLink server to take an action, you must provide a script for the event.

You can write synchronization scripts for connection-level events and for events for each table in the remote database. You save these scripts on the consolidated database.

You can write scripts using SQL, Java, or .NET. For more information about event scripts and writing them in the MobiLink Synchronization plug-in in Sybase Central, see “Preparing consolidated databases”.

The MobiLink synchronization SQL Anywhere client

SQL Anywhere clients at remote sites initiate synchronization by running a command-line utility called dbmlsync. This utility synchronizes one or more subscriptions in a remote database with the MobiLink synchronization server. Subscriptions are described in “Publications, articles, and users”. For more information about the dbmlsync utility and its options, see “dbmlsync utility” in the index of the SQL Anywhere online books.

In PocketBuilder, synchronization objects that you create with the MobiLink Synchronization for ASA wizard manage the dbmlsync process. For more information, see “Working with PocketBuilder synchronization objects”.

A different PocketBuilder wizard, the MobiLink Sync User and Subscription Maintenance wizard, lets you provide application users with the ability to create user names and subscriptions in a remote database. For more information about this wizard, see the chapter on managing the database in the PocketBuilder User’s Guide.

The MobiLink synchronization UltraLite client

One of the major differences in synchronizing an UltraLite database instead of a SQL Anywhere database is that there are no subscriptions in an UltraLite database. By default, all tables in an UltraLite remote database are updated during synchronization, although you can create publications in the database to restrict the updates to specific tables. Another difference is that the MobiLink synchronization call is made directly on the connection object to the remote UltraLite database, rather than through an outside call to a separate synchronization utility.

MobiLink synchronization requires matching publications to be defined in both the consolidated and remote databases, and synchronization scripts to be defined on the consolidated databases. “Preparing to use the wizard for remote UltraLite databases” describes the steps you must take to prepare the databases for synchronization using utilities you can run from the Database painter. You can prepare the databases before or after running the UltraLite Synchronization wizard that helps you integrate MobiLink synchronization with your PocketBuilder applications.

For more information on the UltraLite Synchronization wizard, see the Managing Databases chapter in the User’s Guide.

Publications, articles, and users

A publication is a database object on the remote database that identifies tables and columns to be synchronized. Each publication can contain one or more articles. An article is a database object that represents a whole table, or a subset of the columns and rows in a table.

In MobiLink 9, a MobiLink user is a database object that uniquely identifies a remote database, and is also used to authenticate a person who synchronizes. There is one MobiLink user name for each remote database in the MobiLink system.

In MobiLink 10, a MobiLink user is used only to authenticate a person who synchronizes. User names do not need to be unique. Instead, an identifier called a remote ID uniquely identifies a remote database. The remote ID is stored in the remote database. MobiLink generates a remote ID the first time a remote database synchronizes to a central data source, or any time it encounters a NULL value for the remote ID. The remote ID is created automatically as a GUID, but you can set it to any string that has meaning to you.

The remote ID makes it easier for the same MobiLink user to synchronize different sets of data in different remote databases. For SQL Anywhere 10 remote databases, the MobiLink server tracks synchronization progress by remote ID and subscription. In UltraLite 10 remote databases, the remote ID is also useful for allowing multiple MobiLink users to synchronize the same remote database. For these databases, the MobiLink server tracks synchronization progress by remote ID and publication.

Every script that accepts the MobiLink user name as a parameter now also accepts a remote_id parameter. The remote_id parameter is available only if you use named parameters.

In both versions 9 and 10, MobiLink users are created on the remote database and registered on the consolidated database. You can register users with the mluser utility, the mlsrv10 -zu option, or in other ways. Once registered, MobiLink user names are stored in the ml_user system table on the consolidated database.

Subscriptions

A subscription associates a user with one or more publications. It specifies the synchronization protocol (such as TCP/IP, HTTP, or HTTPS), address (such as myserver.acmetools.com), and additional optional connection and extended options.

All of these objects are created in the remote database, although subscriptions are not used with UltraLite databases. In Sybase Central, you create publications, users, and subscriptions using the SQL Anywhere plug-in, not the MobiLink Synchronization plug-in. For more information, see “Creating remote databases”.

The MobiLink Sync User and Subscription Maintenance wizard creates objects that allow a PocketBuilder application user to create MobiLink users and subscriptions in a remote database. For more information, see the chapter on managing the database in the PocketBuilder User’s Guide.

Create Synchronization Model wizard

The MobiLink 10 plug-in for Sybase Central provides the Create Synchronization Model wizard to help you set up synchronization between a remote database and a consolidated database. You can use the wizard to create scripts, publications, users, and so on. You can also use the wizard to create the remote database and all its objects based on the schema of a consolidated database. You start the wizard by selecting the Tools>MobiLink 10>Setup MobiLink Synchronization menu item or by clicking “Create a Synchronization Model” in the Sybase Central Task view.

The synchronization process

For remote SQL Anywhere databases Dbmlsync connects to the remote database using TCP/IP, HTTP, or HTTPS, and prepares a stream of data (the upload stream) to be uploaded to the consolidated database. Dbmlsync uses information contained in the transaction log of the remote database to build the upload stream. The upload stream contains the MobiLink user name and password, the version of synchronization scripts to use, the last synchronization timestamp, the schema of tables and columns in the publication, and the net result of all inserts, updates, and deletes since the last synchronization.

After building the upload stream, dbmlsync uses information stored in the specified publication and subscription to connect to the MobiLink synchronization server and exchange data.

For remote UltraLite databases The Synchronize call on the connection object to the remote database uses the selected communication stream (TCP/IP, HTTP, or HTTPS) and prepares a stream of data to be uploaded to the consolidated database. Information passed in a structure object is used to connect to the MobiLink synchronization server and exchange data.

For all remote databases When the MobiLink synchronization server receives data, it updates the consolidated database, then builds a download stream that contains all relevant changes and sends it back to the remote site. At the end of each successful synchronization, the consolidated and remote databases are consistent. Either a whole transaction is synchronized, or none of it is synchronized. This ensures transactional integrity at each database.