BRV
BRV

Reputation: 1

Microsoft Sync Framework - scope and tracking for column values

I was tasked to figure out how this system works, and I am barely a Novice when it comes to these matters so be kind.

I have my sync up and running with a sample DB for testing. I am using Visual Studio and am in C#. Below is my code for current Provision for sync.

        // define a new scope named ProductsScope
        DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("ProductsScope");

        // get the description of the Products table from SyncDB dtabase
        DbSyncTableDescription tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Products", serverConn);

        // add the table description to the sync scope definition
        scopeDesc.Tables.Add(tableDesc);

        // setting my provision

        // create a server scope provisioning object based on the ProductScope
        SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc);

        // skipping the creation of table since table already exists on server
        serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);

        // start the provisioning process
        serverProvision.Apply();

And here is my code for sync.

 // create the sync orhcestrator
        SyncOrchestrator syncOrchestrator = new SyncOrchestrator();

        // set local provider of orchestrator to a CE sync provider associated with the 
        // ProductsScope in the SyncCompactDB compact client database
        syncOrchestrator.LocalProvider = new SqlSyncProvider("ProductsScope", clientConn);

        // set the remote provider of orchestrator to a server sync provider associated with
        // the ProductsScope in the SyncDB server database
        syncOrchestrator.RemoteProvider = new SqlSyncProvider("ProductsScope", serverConn);

        // set the direction of sync session to Upload and Download
        syncOrchestrator.Direction = SyncDirectionOrder.UploadAndDownload;

        // subscribe for errors that occur when applying changes to the client
        ((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);
        ((SqlSyncProvider)syncOrchestrator.RemoteProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);

        // execute the synchronization process
        SyncOperationStatistics syncStats = syncOrchestrator.Synchronize();

        //


        // this will show me the statistics after sync
        Console.WriteLine("Start Time: " + syncStats.SyncStartTime);
        Console.WriteLine("Total Changes Uploaded: " + syncStats.UploadChangesTotal);
        Console.WriteLine("Total Changes Downloaded: " + syncStats.DownloadChangesTotal);
        Console.WriteLine("Complete Time: " + syncStats.SyncEndTime);
        Console.WriteLine(String.Empty);}

        static void Program_ApplyChangeFailed(object sender, DbApplyChangeFailedEventArgs e)

{

At this point the sync is a complete rewrite of a row of data. What I am looking for a is a little instruction on setting the sync up to recognize changes made to individual columns(not sure if I am saying that correctly).

If for example:

Column   ID (PK)    Name        Phone      Address
 Row     1          John Smith  555-5555   123 Anywhere St
 Row     2          Jane Smith  555-5555   124 Anywhere St

sales rep one changes the Address in row 1 to 125 Anywhere, and sales rep two changes the phone in row 1 to 555-5556, is there a way to set up what is tracked for changes so that my final result would be both sales reps having:

Column   ID (PK)  Name        Phone     Address
Row      1        John Smith  555-5556  125 Anywhere St
Row      2        Jane Smith  555-5555  124 Anywhere St

after sync has been completed. As I said currently it takes the entire row and rewrites to which ever was last. Resulting in changes being made to the same record by multiple users no being processed correctly.

I am sure this has to do with how the scope, and tracking are set up, but Google is not turning up any answers. Any snips, links, or suggestions would be great.

Upvotes: 0

Views: 1086

Answers (1)

JuneT
JuneT

Reputation: 7860

Sync Framework change tracking is at the row level. It doesnt specifically record which column was changed, only the fact that a row was inserted/updated/deleted.

if a row has been updated in more than one replica, it will cause a conflict. You should be able to catch the conflict in the ApplyChangeFailed event and decide how to resolve the conflict (e.g., server wins, client wins, do custom processing on the row, etc...)

Upvotes: 1

Related Questions