This demonstration synchronizes spatial data stored inside a consolidated database to a SQL Anywhere remote database.
If you install different versions of SQL Anywhere, please ensure that your Windows PATH environment variable includes the SQL Anywhere 12 directory before any other SQL Anywhere directories. The default directories are: C:\Program Files\SQL Anywhere 12\bin32 for Windows x86 and C:\Program Files\SQL Anywhere 12\bin64 for Windows x64.
- Open a Command Prompt and create a directory "SpatialSync" to store the sample's files.
- Extract the compressed archive SpatialSyncModel.zip into that directory. It contains the file "SpatialSyncModel.mlsm" that defines the synchronization model.
- Navigate to that directory and run the following commands to create the sample consolidated database:
copy "%SQLANY12%\scripts\mkdemo.sql" .
xcopy "%SQLANY12%\scripts\adata" .\adata\*.*
dbsrv12 spatialsync.db -x tcpip
dbisql -c "eng=spatialsync;uid=dba;pwd=sql" READ mkdemo.sql
dbdsn -c "uid=dba;pwd=sql;eng=spatialsync" -ws SpatialSyncDemo_ConsDB
Creating the Synchronization Project and Configuring the Consolidated Database
Using the Create Project wizard, you can define a new MobiLink project that contains all information regarding the MobiLink sychronization environment.
- Open Sybase Central and select Create a project from the MobiLink tasks.
- Name the project "Spatial Sync" and enter the location "C:\SpatialSync". Click Next.
- Check Add a consolidated database to the project and enter the following information:
Database display name: Central Database - Spatial Sync
Connection string: dsn=SpatialSyncDemo_ConsDB;uid=dba;pwd=sql
- Select Import an existing model and browse to the file "SpatialSyncModel.mlsm". Click Next.
- Check Add a Remote Schema Name to the project and enter the name "SpatialSyncSchema". Select SQL Anywhere as the database type.
- Back at the main Sybase Central screen, click Add a consolidated database from the project setup tasks.
- Enter the following information in the Add Consolidated Database wizard:
Database type: SQL Anywhere
User ID: dba
Action: Connect with an ODBC data source
ODBC Data Source Name : SpatialSyncDemo_ConsDB
Click Next and then Finish.
You will be asked to install the MobiLink system setup tables in the consolidated database. Click Yes to continue and then OK when the task completes.
Note: Sybase Central may issue an error at this point. If so, you may choose to send us the error report by clicking "Send Error Report". You may also decline to do so by clicking "Don't Send".
Click on "Resume" and then "OK" to continue working in Sybase Central. Click on "Cancel" to terminate the wizard. Please follow these additional steps:
- Switch to the folders view (use the toolbar) and expand MobiLink 12, Spatial Sync, and Consolidated Databases.
- Right-click on SpatialSyncDemo_ConsDB - DBA and select Check MobiLink System Setup from the popup menu.
- You will be asked to install the MobiLink system setup under the owner DBA, click Yes.
- Click OK after the operation completes.
Viewing the Synchronization Model
Switch to the folders view in Sybase Central (use the toolbar), expand "Sync Models" in the left panel and click on "SpatialSyncModel". The table mappings for this model appear on the right panel.
Notice that in this model, we are synchronizing two tables and one of them contains spatial data (SpatialShapes). For more information about synchronization models, please refer to the online documentation.
Deploying the Synchronization Model
- In the left panel, right-click on "SpatialSyncModel" and select Deploy. The Deploy Sychronization Model wizard appears.
- Specify to deploy all three components and click Next.
- Make sure to select "SpatialSyncDemo_ConsDB" as the consolidated database. Click Next.
- Click Yes to create the necessary directory structure.
- Select to create a new SQL Anywhere remote database. Click Next.
- Keep the default settings in the New SQL Anywhere Remtoe Database page. Click Next, then Yes to create the necessary directory structure.
- Set the user name to "ml_user" and password to "sql". Ensure to check the option to register this user in the consolidated database. Set the subscription to "SpatialSync_pub".
- Keep the TCP/IP setting for the stream parameter and change the port number if required. Click Next.
- Set the host name to your machine name. Use default settings for the remainder options, so click Finish. Click Yes on any dialogs that ask you to create the necessary directory structure.
- Click Close after the model successfully deploys.
Starting the MobiLink Server
The Deploy Synchronization Model wizard generated a batch file that you can use to start the MobiLink server inside the folder "mlsrv ". Using the Command Prompt, change to that directory and run the file as follows:
The MobiLink server dialog appears and is ready to accept incoming synchornization requests.
Synchronizing the Remote Database
The Deploy Synchronization Wizard also generated an empty SQL Anywhere remote database and a batch file to initiate data synchronization inside the folder "remote". Using the Command Prompt, change to that directory and the following commands:
- Start the remote database
- Synchronize the database
The MobiLink Synchronization Client window appears showing the progress. Click Shut down when the synchronization succeeds.
Viewing the Spatial Data in the Remote Database
- Using the Command Prompt, launch Interactive SQL and connect to the remote database by running the following command:
dbisql -c "eng=SpatialSyncModel_remote;uid=dba;pwd=sql"
- In Interactive SQL, execute the following statement:
SELECT * FROM GROUPO.SpatialShapes;
- In the Results panel, select the second row and click on the Shape column. A menu box appears at the end of the row. Click on this menu box.
- Select View in Window to view the value of the column "Shape". Click the tab Spatial Preview to show the object.
- Click OK to close the dialog.
- From the Tools menu, select Spatial Viewer and execute the statement SELECT * FROM GROUPO.SpatialShapes;
- All the spatial data is plotted in the viewer.
This concludes the demonstration. Close Interactive SQL.
In Sybase Central, click on "MobiLink 12" in the left panel. If you are asked to save changes, click No. The project "Spatial Sync" appears in the right panel. You may delete this project. Close Sybase Central.
Shut down the databases and the MobiLink synchronization server by running these commands:
dbstop -c "eng=SpatialSyncModel_remote;uid=dba;pwd=sql"
dbstop -y -c "eng=spatialsync;uid=dba;pwd=sql"
Remove the sample's ODBC DSN by running this command:
dbdsn -y -ds SpatialSyncDemo_ConsDB
You may now delete the contents of the folder "SpatialSync" and remove that directory.