Collection Contents Index Setting up the remote database Restoring the database and database settings pdf/chap11.pdf

First Guide to SQL Anywhere Studio
   PART 2. Getting Results with SQL Anywhere Studio
     CHAPTER 11. Replicating Data with SQL Remote       

Start replicating data


You now have a replication system in place. In this section, data is replicated from the consolidated database to the remote database, and from the remote to the consolidated database.

Top of page  Enter data at the consolidated database

First, enter a row at the consolidated database.

  To enter data at the consolidated database:
  1. Connect to the sample database from Interactive SQL as user ID dba, with password sql.

  2. Enter and commit a row into the department table:

    INSERT INTO department (dept_id, dept_name)
    VALUES (202, 'Eastern Sales') ;
    COMMIT ;
  3. Confirm that the data is entered by viewing the data in the tables:

    SELECT * 
    FROM Department

The next step is to send the relevant rows to the remote database.

Top of page  Send data from the consolidated database

To send the rows to the remote database, you must run the Message Agent at the consolidated database. The dbremote program is the Message Agent for Adaptive Server Anywhere.

  To send the data to the remote database:
  1. From a command prompt, change to your tutorial directory. For example,

    > c:
    > cd \tutorial
  2. Enter the following statement at the command line to run the Message Agent against the consolidated database:

    dbremote -c "dbn=asademo;uid=dba;pwd=sql"

    Use the absolute path (above) to link to the database file or use the path which is relative to your server. For example, if your server is in the C:\tutorial\dba directory, you can use the statement:

    dbremote -c "dbn=..\asademo.db;uid=dba;pwd=sql"
  3. Click Shutdown on the Message Agent window to stop the Message Agent when the messages have been sent. The Message Agent window displays the message Execution completed when all processing is complete.

Top of page  Receive data at the remote database

To receive the insert statement at the remote database, you must run the Message Agent, dbremote, at the remote database.

  To receive data at the remote database:
  1. From a command prompt, change to your tutorial directory. For example,

    > c:
    > cd \tutorial
  2. Enter the following statement at the command line to run the Message Agent against the field database:

    dbremote -c "dbf=C:\tutorial\field.db;uid=field;pwd=field"

    Use the absolute path (above) to link to the database file or use the path which is relative to your server. For example, if your server is in the C:\tutorial\dba directory, you can use the statement:

    dbremote -c "dbf=..\field.db;uid=field;pwd=field"
  3. Click Shutdown on the Message Agent window to stop the Message Agent when the messages have been processed. The Message Agent window displays the message Execution completed when all processing is complete.

Notes 

The Message Agent window displays status information while running. This information can be output to a log file for record keeping in a real setup. You will see that the Message Agent first receives a message from asademo, and then sends a message. This return message contains confirmation of successful receipt of the replication update; such confirmations are part of the SQL Remote message tracking system that ensures message delivery even in the event of message system errors.

Depending on the current status of the database, there are three different connectivity parameters you can use to connect to a database:

Top of page  Verify that the data has arrived

Connect to the field database using Interactive SQL, and inspect the department table, to see that the row has been received.

  To verify that the data has arrived:
  1. Connect to the field database using Interactive SQL.

  2. Inspect the department table by typing the following statement:

    SELECT * 
    FROM dba.department

    You will see that the department table contains the row entered at the consolidated database.

Top of page  Replicate from the remote database to the consolidated database

Now try entering data at the remote database and sending it to the consolidated database. Only the outlines are presented here.

  To replicate data from the remote database to the consolidated database:
  1. Connect to the field database from Interactive SQL.

  2. INSERT a row at the remote database. For example

    INSERT 
    INTO dba.Department (dept_id, dept_name) 
    VALUES (203, 'Western Sales')
  3. COMMIT the row.

    COMMIT;
  4. With the field.db database running, run dbremote to send the message to the consolidated database.

    dbremote -c "dbn=field;uid=field;pwd=field"
  5. With the asademo.db database running, run dbremote to receive the message at the consolidated database:

    dbremote -c "dbn=asademo;uid=dba;pwd=sql"
  6. Connect to the consolidated database and display the department table:

    SELECT *
    FROM department
Top of page  

Collection Contents Index Setting up the remote database Restoring the database and database settings pdf/chap11.pdf