Title: Implementing Replication with Microsoft Access and JRO
Question: Access makes it easy for you to implement a full featured replication mechanism. This is How.
Answer:
First of all create an instance of a replica object.
var
FReplica : Replica;
begin
FReplica := CoReplica.Create;
FReplica.ActiveConnection := DM.AdoConnection.ConnectionObject;
//DM.AdoConnection is a TADOConnection object
end;
1.
The first thing that you need is an access database that is replicable. FReplica.ReplicaType tells you if your database of the current connection is already replicable or not.
Result:
jrRepTypeNotReplicable:
The database has not been prepared for replication.
jrRepTypeDesignMaster:
Your database is fully replicable and is design master in addition. That means that in case of conflict this database will be dominant. Design changes can only be made in design master databases.
jrRepTypeFull:
The database is a full replicable copy of a design master database or another jrRepTypeFull-Database.
jrRepTypePartial:
The database is a partial copy of a design master database or another jrRepTypeFull-Database.
In case of jrRepTypeNotReplicable you have to make your database replicable first:
FReplica.MakeReplicable(FDBPath,FALSE);
Your connection must be closed. I suggest to free the TADOConnection-Object and close your application after calling MakeReplica. This is not a problem because this will only happen once.
This will make your database replicable and set the DesignMaster property to true.
2.
Now you can create full replicable copys of your design master database, as much as you like.
FReplica.CreateReplica('C:\MyDatabase.mdb','AnyDescription',jrRepTypeFull,jrRepVisibilityGlobal,1,jrRepUpdFull);
3.
Now you will have a design master database and n full replicable copies. You may synchronize your databases now.
FReplica.Synchronize('C:\MyDatabase2',jrSyncTypeImpExp,jrSyncModeDirect);
Instead of using jrSyncTypeImpExp (meaning that replication will occur in both directions) you could use jrSyncTypeImport or jrSyncTypeExport instead.
After any replication conflicts may have occured. The JET Engine will create tables after the following convention: TABLENAME+_conflict. All records with conflicts are stored in these tables. But to find out what tables are that had any conflicts create a Table (TADOTable).
TableConflict.Recordset := _RecordSet(FReplica.ConflictTables);
TableConflict.Open;
while not TableConflict.EOF do
begin
ShowMessage('Table: '+TableConflict.Fields[0].Text+' Conflict-
Table: '+TableConflicts.Fields[1].Text);
TableConflict.Next;
end;
4.
To synchronize over the internet or using a modem or an ISDN adapter you could use the Microsoft Replication Manager that ships with Office 2000 Developer Edition. This tool, however, is hard to set up. I suggest that you enable one computer to receive calls from outside using RAS and other computer to call that first computer. You would need a shared network path on the first computer.
FReplica.Synchronize('\\COMPUTER1\\SHAREDDrive\MyDatabase2.mdb',jrSyncTypeImpExp,jrSyncModeDirect);