locked
Parameter based filtered scope over n-tier architecture. RRS feed

  • Question

  • Hi

    I've followed the instructions here http://jtabadero.wordpress.com/2010/09/02/sync-framework-provisioning/ to create a scope template and a parameter based scope that uses the template but my sync session still synchronises all rows. I suspect that it's due to the direction I'm syncing but that's just a guess.

    Here's my setup in broad strokes. There will be several local apps pushing up orders to the remote app, the remote app simply approve or rejects orders. I want the local app to sync new orders up and only updates to it's own orders  or approved orders from other clients back down.

    I've got two peers, my LocalProvider is a SqlSyncProvider connected to a LocalDB instance, the RemoteProvider is a proxy via WCF services to another LocalDB instance. 

    I've created a broad scope for TableA called SyncTableA (I did this before I started working on a filtered scope).

    I've got a  template scope for TableA called SyncTableA_Filtered. My template is defined as follows..

    SqlSyncScopeProvisioning serverTemplate = new SqlSyncScopeProvisioning(connection, scopeDesc, SqlSyncScopeProvisioningType.Template);
    serverTemplate.Tables["TableA"].AddFilterColumn("ClientId");
    serverTemplate.Tables["TableA"].AddFilterColumn("Status");
    serverTemplate.Tables["TableA"].FilterClause = "[side].[ClientId] = @clientId or [side].[Status] = 2";
    SqlParameter param = new SqlParameter("@clientId", SqlDbType.UniqueIdentifier);
    serverTemplate.Tables["TableA"].FilterParameters.Add(param);
    serverTemplate.SetCreateProceduresForAdditionalScopeDefault(DbSyncCreationOption.Create);
    serverTemplate.Apply();

    I've directly created this template scope on my local database and my remote database. (not via a proxy, I executed this with two different connections passed to the SqlSyncScopeProvisioning constructor.

    Then I've created a scope from the template called SyncTableA_Filtered-Me, and applied it to the local database. 

    Then I get the scope from the local database and create it on the remote database.

    DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope("SyncTableA_Filtered-Me", sqlConnection);
    remote.CreateScopeDescription(scopeDesc);

    I insert a few records locally, sync them up to the server, fake insert some records from other clients on the server, approve a few of them and synchronise again. Every fake record from the other client is downloaded, the filter doesn't work.

    Friday, February 8, 2013 3:28 PM

All replies

  • GetDescriptionForScope doesnt pick the filter defined for a scope.

    if you've created the template on the remote database, why dont you create the scope from that template as well?

    also, you mentioned you already have a scope containing the same table, can you check how many selectchanges stored procedure you have on that table? confirm that your scope template is not actually reusing the select changes stored proc from the first scope.

    if you dont need the first scope, i suggest you deprovision it.

    Saturday, February 9, 2013 1:19 AM
  • Yeah that makes sense. I can just extend my service interface to "manually" create the scope from the template on the remote database rather than exporting it from the local database. I'll give it a go on Monday.

    Thanks June, (also thanks for the help in your blog comments recently too)

    Saturday, February 9, 2013 6:50 PM