0
votes

I am developing N-Tier sync application using the following code example (http://code.msdn.microsoft.com/Database-SyncSQL-Server-e97d1208) and working on conflict resolution.

To resolve the conflict I am using syncProvider.ApplyChangeFailed event For both local sync provider and remote sync provider.

syncProvider.ApplyChangeFailed event is not fire on local sync provider. Interesting thing is this even fire on remote proxy provider.

Also I have tried with

localProvider.Configuration.CollisionConflictResolutionPolicy = CollisionConflictResolutionPolicy.RenameDestination ;
           localProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.ApplicationDefined   ;

         remoteProvider.Configuration.CollisionConflictResolutionPolicy = CollisionConflictResolutionPolicy.RenameSource ;
         remoteProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.DestinationWins  ; 

But so far no luck.

I am greatly appreciate someone can guide me on this issue.

3

3 Answers

3
votes

the ApplyChangeFailed Event on the local provider fires when there's a conflict applying on the local provider

the ApplyChangeFailed Event on the remote provider is fired when there's a conflict on the remote provider.

meaning, they will be fired separately. a conflict on the remote side will not cause the local providers ApplyChangeFailed event to fire and vice versa.

the SqlSyncProvider will not allow you to set the conflict resolution policy via the Configuration property. if you look at the documentation, it clearly states that the Configuration property is not implemented by the RelationalSyncProvider from which the SqlSyncProvider inherits from.

To set the conflict resolution, you have to do it inside the ApplyChangeFailed event. for every conflict, you can set the Action property to the corresponding conflict resolution that you want.

see: How to: Handle Data Conflicts and Errors for Database Synchronization (SQL Server)

0
votes

Here is my source code for SqlSync provider init. Could you please gude me is there any problem with initating

public      SqlSyncProvider ConfigureSqlSyncProvider(SqlDatabase database , IList<string> tableNames )
       {
           SqlSyncProvider syncProvider = new SqlSyncProvider();


                   syncProvider.ObjectSchema = Constant.ObjectScehamPrefix;
           syncProvider.ScopeName = (Constant.ScopeName );
             //syncProvider.Configuration.ConflictResolutionPolicy = ConflictResolutionPolicy.SourceWins  ;
           syncProvider.Connection = new SqlConnection( database.ConnectionString );
           DbSyncScopeDescription dbSyncScopeDes = new DbSyncScopeDescription(Constant.ScopeName );
           SqlSyncScopeProvisioning serverConfig = new SqlSyncScopeProvisioning((SqlConnection)syncProvider.Connection);
           serverConfig.ObjectSchema = Constant.ObjectScehamPrefix;



           if(!serverConfig.ScopeExists(Constant.ScopeName ))
           {

              // DbSyncTableDescription newTableDescription = new DbSyncTableDescription("Profile.Address");
               DbSyncTableDescription geoTable = SqlSyncDescriptionBuilder.GetDescriptionForTable(  tableNames[0],
                                                                                            (SqlConnection)
                                                                                            syncProvider.Connection);

               dbSyncScopeDes.Tables.Add(geoTable);
               serverConfig.PopulateFromScopeDescription(dbSyncScopeDes );
               serverConfig.SetCreateTableDefault(DbSyncCreationOption.Skip );
               serverConfig.Apply();
           }

                syncProvider.ApplyChangeFailed += provider_ApplyChangeFailed; 

           return syncProvider;
       }
0
votes

Thanks for the answers and all the helps. i found out the issue. My local provider database was polluted database that run differnt sync scope. i have taken the fresh database and run the sync and tested for conflict resolution. all good. ApplyChangeFailed event fire without any trouble.