How do I sync both ways?

jw970170jw970170 Posts: 16
edited November 5, 2007 1:23PM in SQL Toolkit Previous Versions
Hi,

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.
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);

Comments

  • Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
    Hi,

    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.
    block2 = provider.GetMigrationSQL(session, false);
    executor.ExecuteBlock(block2, LocalServer, LocalDatabase, false, LocalUserName, LocalPassword);
    
  • thank you so much. Worked perfectly
Sign In or Register to comment.