| Author |
Message |
jw970170
Joined: 01 Nov 2007 Posts: 12
|
Posted: Mon Nov 05, 2007 5:11 pm Post subject: How do I sync both ways? |
|
|
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.
| Code: |
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);
|
|
|
| Back to top |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6348 Location: Red Gate Software
|
Posted: Mon Nov 05, 2007 6:49 pm Post subject: |
|
|
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.
| Code: |
block2 = provider.GetMigrationSQL(session, false);
executor.ExecuteBlock(block2, LocalServer, LocalDatabase, false, LocalUserName, LocalPassword); |
_________________ Brian Donahue
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
jw970170
Joined: 01 Nov 2007 Posts: 12
|
Posted: Mon Nov 05, 2007 7:23 pm Post subject: |
|
|
| thank you so much. Worked perfectly |
|
| Back to top |
|
 |
|
|
All times are GMT + 1 Hour
|
| Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group