Reputation: 655
I've been made a few tests using Sync framework 2.1 to sync two databases, but i keep having some troubles when i change the schema of databases.
My scenario is:
Two sql server databases syncked and with the same schema.
I add a new Column to some Table at remote database
Re-provisioning the remote database
Try to sync again.
At the step 4 i get an exception indicates that i have a new column at remote Db and that Column doesnt exist at local Db.
So, what i want to do is get the information about that new column such as: Column Name, the Table that holds the Column, and the data type of Column. In order to add that new Column in Local Database.
Does anyone know how to get that information?
Upvotes: 0
Views: 123
Reputation: 7860
Sync Fx don't track and sync schema changes. if you added a column on the remote database and reprovision it, don't expect the destination database to actually receive the new table and scope definition.
the only thing the framework knows about your schema is what you tell it during the provisioning. anything that happens to your schema after provisioning doesn't get reflected in the scope definition.
you can get away with comparing table schemas between source and destination using the approach that Mahesh mentioned above, grab the table descriptions and compare them (e.g., what column in source is not in target).
you can then deprovision and reprovision the scopes.
but then that introduces another problem, your source and destination databases already contains data. so you will run to conflicts on your first sync. depending on the number of rows, that's going to be a slow sync.
if you dont have that many rows to sync, the simplier solution is to simply drop the destination tables and have Sync Fx recreate the tables with the new scope definition.
Upvotes: 1
Reputation: 2757
If you want to change schema in already configured sync scope you need to first de-provision both databases in given scopes. Then do the schema changes and again provision for the given scope. If you want to sync all the column in table you can use following method to get table schemas
tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable( TableName, Connection);
If you want to sync selected columns in table use the method to get table schemas. Column list is list of column name that you need to sync.
SqlSyncDescriptionBuilder.GetDescriptionForTable( TableName, ColumnList, Connection);
Upvotes: 0