How do I sync both ways?

Forum for users of SQL Toolkit 3,4,and 5

How do I sync both ways?

Postby jw970170 » Mon Nov 05, 2007 4:11 pm


I've followed that 'Worked Example' in the API documentation and have been able to sync one of my DBs (the master one) by add and updating rows (I disabled the delete option). After I update the master DB, I want to sync again with the client DB so that the client now reflects the updated master. Is there a way to do this without doing the data compare all over again? I know that the differences in the client from the master are in the TableDifferences property so I don't think I need to do the whole thing all over again.

Here is my code. It updates the mater DB perfectly but I need to update the client after as well.

Code: Select all
dbLocal = new Database();
dbMaster = new Database();

dbLocal.RegisterForDataCompare(new ConnectionProperties(ClientServer, ClientDatabase, ClientUserName, ClientPassword));
dbMaster.RegisterForDataCompare(new ConnectionProperties(MasterServer, MasterDatabase, MasterUserName, MasterPassword));

//Compare the DBs
SchemaMappings mappings = new SchemaMappings();
mappings.CreateMappings(dbLocal, dbMaster);
session = new ComparisonSession();
 session.Options.ComparisonOptions = ComparisonOptions.UseChecksumComparison;
session.CompareDatabases(dbLocal, dbMaster, mappings);

for (int i = 0; i < session.TableDifferences.Count; i++)
     session.TableDifferences[i].SqlSynchronization = SqlSynchronization.UpdateSql | SqlSynchronization.AddSql;
SqlProvider provider = new SqlProvider();
block = provider.GetMigrationSQL(session, true);
BlockExecutor executor = new BlockExecutor();
executor.ExecuteBlock(block, MasterServer, MasterDatabase, false, MasterUserName, MasterPassword);
Posts: 12
Joined: Thu Nov 01, 2007 4:11 pm

Postby Brian Donahue » Mon Nov 05, 2007 5:49 pm


All that you should need to do is change the RunOnTwo argument to the GetMigrationSql method to get the sql script that you would like to run on dbLocal.
Code: Select all
block2 = provider.GetMigrationSQL(session, false);
executor.ExecuteBlock(block2, LocalServer, LocalDatabase, false, LocalUserName, LocalPassword);
Brian Donahue
Posts: 6590
Joined: Mon Aug 23, 2004 9:48 am

Postby jw970170 » Mon Nov 05, 2007 6:23 pm

thank you so much. Worked perfectly
Posts: 12
Joined: Thu Nov 01, 2007 4:11 pm

Return to SQL Toolkit Previous Versions

Who is online

Users browsing this forum: No registered users and 1 guest