none
Synchronize data after changing the filter parameter value

    Question

  • Hello

    I have configured synchronization between (SQL Server 2012 and SQL Server CE) with Sync Framework.

    I have defined a filter template and a sync scope with one parameter. I run the synchronization and everything works fine, I have the data downloaded to the local database.

    Now, I want to change the parameter value and sync again. This is the code I am using.

    var sqlSyncScopeProvisioning = new SqlSyncScopeProvisioning(sqlConnection);
    
    if (sqlSyncScopeProvisioning.ScopeExists(scopeName))
    {
        var scopeDeprovisioning = new SqlSyncScopeDeprovisioning(sqlConnection);
        scopeDeprovisioning.DeprovisionScope(scopeName);
    }
    
    sqlSyncScopeProvisioning = new SqlSyncScopeProvisioning(sqlConnection);
    sqlSyncScopeProvisioning.PopulateFromTemplate(scopeName, scopeTemplate);
    sqlSyncScopeProvisioning.Tables[Constants.TableProducts].FilterParameters["@productId"].Value = productId;
    sqlSyncScopeProvisioning.Tables[Constants.TableTransactions].FilterParameters["@transactionId"].Value = transactionId;
    sqlSyncScopeProvisioning.UserComment = "Filtered products and transactions.";
    sqlSyncScopeProvisioning.Apply();

    This partially works for me. The new data matching the filter criteria for the new parameter value gets downloaded to the local database, but the existing data (from the first sync) still exists.

    Is there an option to keep each time the last synced values and get rid of the old ones?

    Regards,

    Angela

    Tuesday, July 08, 2014 6:27 AM

Answers

  • it depends on what you want to achieve

    if you dont need the old values, why not delete/truncate them when you change filter value?

    why do you need to change filter value?

    instead of changing filter value, why not create another scope for the new value?

    it all depends on what exactly you're after.

    but no, there is no out of the box function for rows going in and out of scope.

    Tuesday, July 08, 2014 8:09 AM
    Moderator

All replies

  • deprovisioning a scope simply removes the scope definition, not the data that was synched in that scope.

    likewise, assuming you don't deprovision and you also update the value in the column used in a filter, Sync Fx does not support rows going in and out of scope.

    Tuesday, July 08, 2014 6:46 AM
    Moderator
  • Hi,

    So is there an "clean" solution to achieve what I want? Also, can I change the filter value without going through deprovision?

    Tuesday, July 08, 2014 7:04 AM
  • it depends on what you want to achieve

    if you dont need the old values, why not delete/truncate them when you change filter value?

    why do you need to change filter value?

    instead of changing filter value, why not create another scope for the new value?

    it all depends on what exactly you're after.

    but no, there is no out of the box function for rows going in and out of scope.

    Tuesday, July 08, 2014 8:09 AM
    Moderator
  • Yes, I tried this solution and it works for me:

    - clear the data in localdatabse

    - create a new scope with the new filter values

    Thursday, July 10, 2014 6:39 AM
  • Hi again

    Just to be sure I want to ask you, it is not possible because of XXX_SelectChanges store procedure to have 2 scopes on the same table, one with filter and the other one without a filter?

    Thursday, July 10, 2014 9:08 AM
  • you can, set the SetCreateProceduresForAdditionalScopeDefault to create an additional SelectChanges sp. but note that while it will create a new SelectChanges SP, they will still share all the other stored procedures so you cannot have different column counts for the scopes.
    Thursday, July 10, 2014 10:50 AM
    Moderator