Introducing SQL Anywhere Studio
Tutorial: Synchronizing Databases with MobiLink
MobiLink synchronization requires that you have compatible consolidated and remote databases, data in database tables, and ODBC data sources for each database.
TipAll command work in the tutorial is assumed to be taking place in the directory you make called C:\MLTutorial. |
The first step is to create each of the databases. In this procedure, you build a consolidated database and a remote database using the dbinit executable from the command prompt.
TipCreating a database file using dbinit is similar to formatting a disk — you have a database file with no user tables or procedures. You create your database schema when you define, within the newly initialized file, various user-defined tables and procedures. |
For more information on the dbinit utility, see Creating a database using the dbinit command-line utility.
To create your database files
At a command prompt, go to the directory you made called Samples\MobiLink\introducing_ML_tutorial directory.
Create a file for your consolidated database. At a command prompt type:
dbinit consol.db
Create a file for your remote database. At a command prompt type:
dbinit remote.db
Verify the successful creation of these database files by typing the following at a command prompt:
dir
Your database files should appear in the directory listing. If not, review your procedures and repeat Steps 1 or 2 as needed.
You are now ready to build ODBC data sources through which you can connect to your Adaptive Server Anywhere databases.
For more information on creating ODBC data sources see The Data Source utility.
To create ODBC data sources
Create your ODBC data source for a consolidated database by typing the following from a command prompt:
dbdsn -w test_consol -y -c "uid=DBA;pwd=SQL;dbf=C:\MLTutorial\consol.db;eng=Consol"
Create an ODBC data source for a remote database by typing the following from a command prompt:
dbdsn -w test_remote -y -c "uid=DBA;pwd=SQL;dbf=C:\MLTutorial\remote.db;eng=remote"
Now you can verify your data sources.
To verify your new data sources
Start the ODBC Administrator:
Choose Start
The ODBC Data Source Administrator appears.
Click the User DSN tab.
Scroll through the list to find your new data sources.
Select a data source and click Configure.
The ODBC Configuration for Adaptive Server Anywhere dialog opens.
On the ODBC tab, test your data source by clicking the Test Connection button.
The MobiLink synchronization server and the MobiLink synchronization client use the ODBC data sources to connect to the consolidated and remote databases, respectively.
You can now create tables for each of your newly initialized databases by executing SQL statements in scripts using Interactive SQL. The scripts contain SQL statements that create tables in the consolidated and remote databases and insert data. The scripts also create synchronization subscriptions and publications on the remote.
To run scripts from Interactive SQL
Start Interactive SQL.
From the Start menu, choose Programs
or
From a command prompt, type dbisql.
Connect to the consolidated database.
Create a table in the consolidated database and add some rows to the table:
Enter the following instructions:
CREATE TABLE cust ( cust_id int default autoincrement primary key, emp_id int, cust_name varchar( 128 ) ); -- add data to cust table INSERT INTO cust ( emp_id, cust_name ) VALUES ( 1, 'cust1' ); INSERT INTO cust ( emp_id, cust_name ) VALUES ( 1, 'cust2' ); INSERT INTO cust ( emp_id, cust_name ) VALUES ( 2, 'cust3' ); COMMIT;
Verify the successful creation of the table:
Enter the following command and verify that three rows are returned:
SELECT * FROM cust
Now repeat steps 2, 3, and 4 for the remote database remote.db, using the following SQL statements. No rows are added to the table in the remote database.
CREATE TABLE cust (cust_id int default autoincrement primary key, emp_id int, cust_name varchar( 128 ) )
The query SELECT * FROM cust should display no rows.
TipIf you need to start your database at any time, the following commands, for the consolidated and remote databases, can be used from the C:\MLTutorial directory:dbeng9 consol.db dbeng9 remote.db |