You are on page 1of 12

MobiLink Synchronization with Microsoft SQL Server and Adaptive Server Anywhere in 30 Minutes

A whitepaper from iAnywhere Solutions, Inc., a subsidiary of Sybase, Inc.

Contents
Synchronizing Microsoft SQL Server with MobiLink Introduction Required Software MobiLink Quick Start Set up the Microsoft SQL Server consolidated database Set up the remote Adaptive Server Anywhere database Create scripts to upload and download data . . . . . . . Run MobiLink synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2 3 3 3 3 3 4 4 4 6 9 9 11 11

MobiLink Synchronization to a Microsoft SQL Server Database in 30 Minutes Set up the Microsoft SQL Server consolidated database . . . . . . . . . . Set up the remote Adaptive Server Anywhere database . . . . . . . . . . Starting the MobiLink synchronization server . . . . . . . . . . . . . . . . Running the MobiLink synchronization client utility . . . . . . . . . . . . . Legal Notice Contact Us . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Copyright 2004 iAnywhere Solutions, Inc.

Synchronizing Microsoft SQL Server with MobiLink


This paper demonstrates how to synchronize data between a Microsoft SQL Server consolidated database and Adaptive Server Anywhere remote databases. It shows how to set up a simple synchronization from scratch using an SQL Server sample database. A single remote database is set up in this paper.

Introduction
MobiLink enables synchronization between a central ODBC-compliant consolidated database and many Adaptive Server Anywhere or UltraLite remote databases. MobiLink synchronization is a component of SQL Anywhere Studio, iAnywhere Solutions comprehensive package for mobile data management. The following diagram shows the major parts of the synchronization system.

Consolidated database server

Adaptive Server Anywhere or UltraLite MobiLink clients

network
ASA

Remote database server

MobiLink synchronization server Remote database

consolidated database This database contains the central copy of all information in the synchronization system. consolidated database server The server, or DBMS, that manages the consolidated database. This server can be one of the following ODBC-compliant databases: Adaptive Server Anywhere, Adaptive Server Enterprise, Oracle, IBM DB2, or Microsoft SQL Server. In this tutorial the consolidated database server is SQL Server. ODBC connection All communication between the MobiLink synchronization server and the consolidated database occurs through an ODBC connection. ODBC allows the synchronization server to utilize a variety of consolidated database systems. In this tutorial, the ODBC connection is made with the SQL Server ODBC driver. MobiLink synchronization server This server, dbmlsrv9, manages the

Copyright 2004 iAnywhere Solutions, Inc. synchronization process and provides the interface between all MobiLink clients and the consolidated database server. network The connection between the MobiLink synchronization server and the MobiLink client (dbmlsync or UltraLite) can use a number of network protocols. This tutorial uses the TCP/IP protocol. MobiLink client The client can be installed on a handheld device such as a Palm Pilot or Pocket PC, a server or desktop computer, or an embedded device such as a cell phone or vending machine. Two types of clients are supported: Adaptive Server Anywhere (used in this tutorial) and UltraLite. Either or both may be used in a single MobiLink installation.

Required Software
A full SQL Anywhere Studio 9.0.1 installation. A full installation of SQL Server 2000 including the Northwind sample database.

MobiLink Quick Start


Following is an overview of the steps required to set up a Microsoft SQL Server database for MobiLink synchronization. Each step is illustrated in detail later in this paper.

Set up the Microsoft SQL Server consolidated database


1. Run a pre-dened SQL script (syncmss.sql) to prepare your Microsoft SQL Server database to be a MobiLink consolidated database. This adds MobiLink tables and stored procedures. 2. Dene an ODBC data source for the Microsoft SQL Server database using the SQL Server ODBC driver.

Set up the remote Adaptive Server Anywhere database


1. Create an Adaptive Server Anywhere database. 2. Migrate a subset of your Microsoft SQL Server schema to the Adaptive Server Anywhere database, including any synchronized tables. 3. Create a remote synchronization publication, synchronization user, and synchronization subscription.

Create scripts to upload and download data


MobiLink uses synchronization scripts to provide exibility in the rules you use to synchronize data. The scripts dene:

Copyright 2004 iAnywhere Solutions, Inc. How data uploaded from the remote database is to be applied to the consolidated database. What data should be downloaded from the consolidated database. These scripts may be individual statements or stored procedure calls stored in your consolidated database. For simple cases you can instruct the MobiLink synchronization server to generate scripts automatically at runtime using a command-line option.

Run MobiLink synchronization


Start the MobiLink synchronization server (dbmlsrv9). This enables the MobiLink server to listen for client synchronization requests. Run the MobiLink synchronization client utility (dbmlsync) to initiate a synchronization session.

MobiLink Synchronization to a Microsoft SQL Server Database in 30 Minutes


The previous section sketched the steps necessary to set up synchronization. This section walks through all these steps in detail. Note: Some examples in this tutorial are presented with Sybase Central. Sybase Central is a database management tool that provides Adaptive Server Anywhere database settings, properties, and utilities in a graphical user interface. It relies heavily on the use of wizards. However, Sybase Central, Interactive SQL, and the command line may be used interchangeably.

Set up the Microsoft SQL Server consolidated database


This tutorial uses Northwind, a sample database commonly used for Microsoft SQL Server demonstrations and training. Installing MobiLink system tables in the Microsoft SQL Server database MobiLink comes with a script called syncmss.sql located in the MobiLink\setup subdirectory of your SQL Anywhere installation. syncmss.sql is a le containing SQL statements to prepare Microsoft SQL Server databases for use as MobiLink consolidated databases. It creates a series of system tables and procedures prefaced with ML_. MobiLink works with these tables and stored procedures during the synchronization process. y To install MobiLink system tables 1. Open SQL Server Query Analyzer.

Copyright 2004 iAnywhere Solutions, Inc. Choose Start Programs Microsoft SQL Server Query Analyser. 2. Select the Northwind sample database. From the DB dropdown menu in the toolbar, choose Northwind. 3. Execute the SQL script. Open syncmss.sql: From the File menu, choose Open. Now select syncmss.sql, located in the MobiLink\setup subdirectory of your SQL Anywhere installation. Press F5 to execute the Query. Dene an ODBC data source for the consolidated database Use the Microsoft SQL Server ODBC driver to dene an ODBC data source for the Northwind sample database. y To dene an ODBC data source for the consolidated database 1. Start the ODBC Administrator: Fromt the Start menu, choose Programs SQL Anywhere 9 Adaptive Server Anywhere ODBC Administrator. The ODBC Data Source Administrator appears. 2. On the User DSN tab, click Add. The Create New Data Source dialog appears. 3. Select SQL Server and click Finish. The Microsoft SQL Server DSN Conguration wizard appears. 4. Enter sqlserver_consolidated as the Name of the data source. Click Next to continue. 5. On the next page, select the appropriate authentication mode for your SQL connection. Click Next to continue. 6. Select Northwind as the default database. Remove check marks from the following: Use ANSI quoted identiers. Use ANSI nulls, paddings and warnings. 7. Accept the remaining default settings and click Finish. Synchronization scripts In this tutorial, you do not manually add synchronization scripts. When you start the MobiLink synchronization server with special command-line options, default scripts are automatically generated. You can use these scripts as a starting point for generating your own scripts. Setup for the Microsoft SQL Server consolidated database is now complete.

Copyright 2004 iAnywhere Solutions, Inc.

Set up the remote Adaptive Server Anywhere database


MobiLink is designed for synchronization involving a consolidated database server and a large number of mobile databases. In this section, you create a single remote database, migrate a selected portion of the consolidated schema, and create a synchronization publication, user, and subscription. One way to create an Adaptive Server Anywhere database is to use the dbinit command-line utility. For this tutorial, we will call the remote database remote1. y To create and start a new Adaptive Server Anywhere remote database 1. At a command prompt, navigate to the directory where you would like to create the database. 2. Type the following command to create the database:
dbinit remote1.db

3. Now, to start the database, type:


dbeng9 remote1.db

Migrating a subset of the Northwind database Microsoft SQL Server schema Migrating a subset of the Northwind schema involves: Connecting to the remote database. Creating a remote server and external login. Using the Sybase Central Data Migration wizard. y To migrate a subset of your Microsoft SQL Server schema to the Adaptive Server Anywhere database 1. Start Sybase Central. From the Start menu, choose Programs SQL Anywhere 9 Sybase Central. 2. Connect to the remote database: Select Adaptive Server Anywhere 9 in the left pane of Sybase Central. From the File menu choose Connect. The Connect dialog appears. On the Identication tab, enter DBA as the User ID and SQL as the password. On the Database tab, enter remote1 as the server name. Click OK to connect. 3. Create a remote server and external login: Start the Remote Server Creation wizard. In the left pane, select the Remote Servers folder. From the File menu choose New Remote Server. The Remote Server Creation wizard starts.

Copyright 2004 iAnywhere Solutions, Inc. Name the remote server my_sqlserver. Click Next to continue. Choose Microsoft SQL Server as the type of server. On the next page of the wizard, enter sqlserver_consolidated in the connection information section. On the nal page of the wizard, choose Create an External Login. Enter the Login name and Password to connect to your Microsoft SQL Server instance. Click Finish to exit the Remote Server Creation wizard. 4. Migrate the Microsoft SQL Server schema: In the left pane, select the Adaptive Server Anywhere 9 plug-in. In the right pane, select the Utilities tab and double-click Migrate Database:

The Data Migration wizard starts. Select remote1 as the destination database. On the next page, select my_sqlserver as the remote server. Click Next to continue. Choose Customers and Employees as the only tables to migrate.

Copyright 2004 iAnywhere Solutions, Inc.

On the nal page of the wizard, clear the Migrate the data option:

Click Finish. The migration of the Microsoft SQL Server schema is now complete. y To create a remote synchronization publication, synchronization user, and synchronization subscription 1. Start Interactive SQL: In the left pane of Sybase Central, select the remote1 database. From the File menu choose Open Interactive SQL. The Connect dialog appears. 2. Enter synchronization information: Execute the following commands in Interactive SQL:

Copyright 2004 iAnywhere Solutions, Inc.

CREATE PUBLICATION sample_pub (TABLE Customers, TABLE Employees); CREATE SYNCHRONIZATION USER ml_user1; CREATE SYNCHRONIZATION SUBSCRIPTION TO sample_pub FOR ml_user1 TYPE TCPIP ADDRESS host=localhost OPTION scriptversion=ver1;

Now you have prepared the remote and consolidated databases and can begin with the synchronization process.

Starting the MobiLink synchronization server


y To run the MobiLink synchronization server (dbmlsrv9) 1. At a command prompt, type the following on a single line:
dbmlsrv9 -c "dsn=sqlserver_consolidated" -o serverOut.txt -v+ -dl -za -zu+ -x tcpip

Note: MobiLink technology also allows you to obfuscate command-line options in a command le. Consult MobiLink documentation about the dbfhide utility for more information. The following table describes each option used with the dbmlsrv9 utility. The options -o, -v, and -dl provide debugging and troubleshooting information. Using these logging options is appropriate in a development environment. For performance reasons, -v and -dl are typically not used in production.
Option -c -o -v+ -dl -za Description Precedes the connection string. Species the message log le serverOut.txt. The -v option species what information is logged. Using -v+ sets maximum verbose logging. Displays all log messages on screen. Turns automated scripting ON. The -za option is typically used to generate scripts as a starting point for writing your own scripts. Scripts are generated the rst time that a remote synchronizes. If the given script version already exists, -za has no effect. Adds new users automatically. Sets the communications protocol and parameters for MobiLink clients.

-zu+ -x

A dialog appears to indicate the MobiLink synchronization server is ready to handle requests:

Running the MobiLink synchronization client utility


The dbmlsync utility initiates MobiLink synchronization for Adaptive Server Anywhere remote databases.

Copyright 2004 iAnywhere Solutions, Inc. y To start the synchronization client 1. At a command prompt, type the following on a single line:
dbmlsync -c "eng=remote1;uid=dba;pwd=sql" -o rem1.txt -v+ -e "SendColumnNames=on"

Below is a description of each option:


Option -c -o -v -e Description Precedes the connection string. Species the message log le rem1.txt. The -v option species what information is logged. Using -v+ sets maximum verbose logging. The -e option species extended options. In this case it is used to send column names to the MobiLink synchronization server (required for automatic scripting). The SendColumnNames parameter is typically used together with the -za or -ze option on the MobiLink synchronization server for automatically generating synchronization scripts.

Once you have started the MobiLink synchronization client, an output screen appears indicating that the MobiLink synchronization succeeded. The data in the Microsoft SQL Server tables now appears in your Adaptive Server Anywhere database. You can check that synchronization has succeeded by checking row values in the remote database. y To check row values on the remote database 1. Open Sybase Central and connect to the remote1 database using the Adaptive Server Anywhere 9 plug-in (if not already connected). 2. Open the Tables folder and choose the Employees Table. On the right pane, select the Data tab. Data downloaded from the Microsoft SQL Server consolidated database appears:

10

Copyright 2004 iAnywhere Solutions, Inc.

Legal Notice
Copyright 2004 iAnywhere Solutions, Inc. All rights reserved. Sybase, the Sybase logo, iAnywhere Solutions, the iAnywhere Solutions logo, Adaptive Server, MobiLink, and SQL Anywhere are trademarks of Sybase, Inc. or its subsidiaries. All other trademarks are property of their respective owners. The information, advice, recommendations, software, documentation, data, services, logos, trademarks, artwork, text, pictures, and other materials (collectively, Materials) contained in this document are owned by Sybase, Inc. and/or its suppliers and are protected by copyright and trademark laws and international treaties. Any such Materials may also be the subject of other intellectual property rights of Sybase and/or its suppliers all of which rights are reserved by Sybase and its suppliers. Nothing in the Materials shall be construed as conferring any license in any Sybase intellectual property or modifying any existing license agreement. The Materials are provided AS IS, without warranties of any kind. SYBASE EXPRESSLY DISCLAIMS ALL REPRESENTATIONS AND WARRANTIES RELATING TO THE MATERIALS, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. Sybase makes no warranty, representation, or guaranty as to the content, sequence, accuracy, timeliness, or completeness of the Materials or that the Materials may be relied upon for any reason. Sybase makes no warranty, representation or guaranty that the Materials will be uninterrupted or error free or that any defects can be corrected. For purposes of this section, Sybase shall include Sybase, Inc., and its divisions, subsidiaries, successors, parent companies, and their employees, partners, principals, agents and representatives, and any third-party providers or sources of Materials.

Contact Us
iAnywhere Solutions Worldwide Headquarters One Sybase Drive, Dublin, CA, 94568 USA Phone 1-800-801-2069 (in US and Canada) Fax 1-519-747-4971 World Wide Web http://www.ianywhere.com E-mail contact.us@ianywhere.com

11

You might also like