In a bi-direction replication the changes that are made in either database are sent to the other one. Each database is a Source and a Target at the same time, so each database has a Capture Process and an Apply Process. This example keeps the schema dbo of two SQL Server databases in sync. The steps are the ones of Basic Replication Configuration.
A change that an Apply Process writes to a database is a change of that database, and the Capture Process of the same database would send it back. Repstance prevents this. The Apply Process writes its position to the table repi.apply_ckpt of the Target Database in the same transaction as the changes. The Capture Process of a SQL Server database recognises these transactions and does not capture them. The parameter skiploopback of the Capture Process says which Apply Processes it ignores: all (the default), none or a list of Apply Process ids (see SQL Server Capture Parameters).
The Capture Process looks for the table repi.apply_ckpt when it starts. So prepare each database as a Source and as a Target before its Capture Process is started. If you prepare a database as a Target later, stop its Capture Process and run it again.
Prepare each database as a Source and as a Target:
repcli>prepare database=source dbtype=mssql server=db-src.example.com port=1433 user=repuser password=Passw0rd123 dbname=testDB
[Completed]: Database [db-src.example.com:1433,testDB] has been prepared.
repcli>prepare database=target dbtype=mssql server=db-src.example.com port=1433 user=repuser password=Passw0rd123 dbname=testDB
[Completed]: Database [db-src.example.com:1433,testDB] has been prepared.
repcli>prepare database=source dbtype=mssql server=db-tgt.example.com port=1433 user=repuser password=Passw0rd123 dbname=testDB
[Completed]: Database [db-tgt.example.com:1433,testDB] has been prepared.
repcli>prepare database=target dbtype=mssql server=db-tgt.example.com port=1433 user=repuser password=Passw0rd123 dbname=testDB
[Completed]: Database [db-tgt.example.com:1433,testDB] has been prepared.Create a Capture Process for each database. This example replicates the data changes (dmlinclude) but not the DDL statements:
repcli>prepare process=capture id=1 dbtype=mssql name=cap1 server=db-src.example.com port=1433 user=repuser password=Passw0rd123 dbname=testDB dmlinclude=dbo.% autostart=1
[Completed]: Capture 1 has been added
repcli>prepare process=capture id=2 dbtype=mssql name=cap2 server=db-tgt.example.com port=1433 user=repuser password=Passw0rd123 dbname=testDB dmlinclude=dbo.% autostart=1
[Completed]: Capture 2 has been addedEach Apply Process reads the Capture Process of the other database: the Apply Process 1 writes to the first database and reads cap2, the Apply Process 2 writes to the second database and reads cap1. repuser=1 makes the Apply Process connect as a replication login. For the objects that were created with the option NOT FOR REPLICATION SQL Server then does not fire the triggers, does not run the cascade actions of the foreign keys and does not count the identity values (see SQL Server Apply Parameters):
repcli>prepare process=apply id=1 dbtype=mssql capturename=cap2 server=db-src.example.com port=1433 user=repuser password=Passw0rd123 dbname=testDB repuser=1 autostart=1
[Completed]: Apply 1 has been added
repcli>prepare process=apply id=2 dbtype=mssql capturename=cap1 server=db-tgt.example.com port=1433 user=repuser password=Passw0rd123 dbname=testDB repuser=1 autostart=1
[Completed]: Apply 2 has been addedThe command status shows the two Capture Processes and the two Apply Processes (see Status of any Capture or Apply Processes). Change a row in one database: it appears in the other database once, and it does not come back. To check that the two databases are the same, compare them: DATA COMPARISON.
| Value | What the Capture Process does |
|---|---|
| all (the default) | It ignores the changes of all the Apply Processes. Use it for a bi-direction replication, as in this example. |
| none | It captures the changes of the Apply Processes too. Use it for a database that sends on the changes it has received, for example to a third database. |
| 2,3 (a list of ids) | It ignores the changes of the listed Apply Processes only. For an Oracle Source an id list is used for DDL only: use all. |
Prev page:
Multi-Target ReplicationNext page:
Objects and Data Transformation