Red Gate forums :: View topic - How do I sync both ways?
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Toolkit Previous Versions
SQL Toolkit Previous Versions forum

How do I sync both ways?

Search in SQL Toolkit Previous Versions forum
Post new topic   Reply to topic
Jump to:  
Author Message
jw970170



Joined: 01 Nov 2007
Posts: 12

PostPosted: Mon Nov 05, 2007 5:11 pm    Post subject: How do I sync both ways? Reply with quote

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
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6641

PostPosted: Mon Nov 05, 2007 6:49 pm    Post subject: Reply with quote

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);
Back to top
View user's profile Send private message
jw970170



Joined: 01 Nov 2007
Posts: 12

PostPosted: Mon Nov 05, 2007 7:23 pm    Post subject: Reply with quote

thank you so much. Worked perfectly
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic 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