How to sync only specific rows from server RRS feed

  • Question

  • Hello,

      I am developing a windows mobile 6.5 application. I am using Microsoft Sync Framework to sync the server and mobile database. I am able to sync the entire table from server to my mobile. But I need to get only the rows whose UserID = somethg .. I need to sync only specific rows from the server to my mobile. How should I do this ? Please help me with the solution.

    Thank you,


    Wednesday, June 22, 2011 12:55 AM


All replies

  • if you used the Local Database Cache Wizard, then you are not able to specify a filter. you can however modify the generated code to specify a filter.

    see: http://msdn.microsoft.com/en-us/library/bb726003(v=SQL.110).aspx and http://jtabadero.wordpress.com/2010/03/17/adding-filter-to-local-database-cache-generated-sync/

    Wednesday, June 22, 2011 1:28 AM
  • Hello,

        Thank you for the reply. The link was very useful. I used Local Database Cache Wizard to create the code. So, I followed the steps provided at the following link to create the filter : http://jtabadero.wordpress.com/2010/03/17/adding-filter-to-local-database-cache-generated-sync/


    When I build the code I am getting the following error:

    Error 1 The type 'Microsoft.Synchronization.Data.ServerSyncProvider' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.Synchronization.Data, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91'. C:\Documents and Settings\Vikky\My Documents\MOM\MobileOrderManagement\MobileOrderManagement\OrderDetailsCache.Client.Designer.cs 316


    Thank you,



    Wednesday, June 22, 2011 8:13 PM
  • After working on this issue, I see that Microsoft Sync Services for devices version 1 SP1 is available. version 2 is not available. 

    And with Microsoft Sync services for devices we dont have Microsoft.Synchronization.Data.Server.dll is not available. But for the code explained in the blog on how to create filters I need to use Microsoft.Synchronization.Data.Server.dll. Please help.


    Thank you.

    Wednesday, June 22, 2011 8:24 PM
  • you'll have to insert the filter on the WCF service side. you can't do it on the mobile device since what you have there to represent the remoteprovider is just a proxy.

    you can also manually edit the SQL generated by the designer to add your filter if you cant use the approach from the blog post.
    Wednesday, June 22, 2011 11:24 PM
  • If i insert the filter on WCF server side how will I send the parameter to the server from my mobile . I am trying to modify the code that is automatically generated from Local Database Cache designer.



    Thursday, June 23, 2011 2:58 AM
  • The AddFilters Function is used on the mobile side of the code. And we are using LocalDataCacheServerSyncProvider in that function. But you are asking me to add the filter in the server side .

    Am I missing something here. Can you please explain in detail . I am new to sync services and mobile application development. So, please help me to understand this.


    Thank you,

    Thursday, June 23, 2011 3:02 AM
  • what am trying to say is you can add the filter clause and the filter parameter in the server side code's SQL, but you would still pass the actual filter value from the client using the sync agents configuration object.

    Thursday, June 23, 2011 3:17 AM
  • On the server side code, we have a file .sync file which is a xml file. The syncAgent object is written in the xml file and I can't find code anywhere to add the filter clause and filter parameter. I can't get the handle of the syncAgent so that I can add filter clause and filter parameters. Where and how can i add the filter clause and filter parameter. 

    Thank you

    Friday, June 24, 2011 3:50 AM
  • look for a file than ends with Designer.cs, that's a partial class that you modify directly or you can extend via another .cs file.

    the syncagent is where you call Synchronize(), you should be able to easily spot that on the client code.

    Friday, June 24, 2011 4:24 AM
  • Hi,

      I completed the code and when I try to run the synchronize I am getting the TargetInvocation exception. 

    InnerException: {"CFFaultException"}

    Stack Trace: "   at Microsoft.Tools.ServiceModel.CFClientBase`1.processReply(Message reply)\r\n   at Microsoft.Tools.ServiceModel.CFClientBase`1.getResult[TRESPONSE](Message reply, CFInvokeInfo info)\r\n   at Microsoft.Tools.ServiceModel.CFClientBase`1.Invoke[TREQUEST,TRESPONSE](CFInvokeInfo info, GetChangesRequest request)\r\n   at OrderDetailsCacheSyncContractClient.GetChanges(GetChangesRequest request)\r\n   at OrderDetailsCacheSyncContractClient.GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession)\r\n   at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)\r\n   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess, StackCrawlMark& stackMark)\r\n   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)\r\n   at Microsoft.Synchronization.Data.ServerSyncProviderProxy.GetChanges(SyncGroupMetadata groupMetadata, SyncSession syncSession)\r\n   at Microsoft.Synchronization.SyncAgent.DownloadChanges(SyncGroupMetadata groupMetadata)\r\n   at Microsoft.Synchronization.SyncAgent.Synchronize()\r\n   at MobileOrderManagement.BusinessLogic.Synchronize.SynchronizeDB()\r\n   at MobileOrderManagement.OpenOrdersPage.OpenOrdersPage_Load(Object sender, EventArgs e)\r\n   at System.Windows.Forms.Form.OnLoad(EventArgs e)\r\n   at System.Windows.Forms.Form._SetVisibleNotify(Boolean fVis)\r\n   at System.Windows.Forms.Control.set_Visible(Boolean value)\r\n   at System.Windows.Forms.Control.Show()\r\n   at MobileOrderManagement.MenuPage.openOrdersButton_Click(Object sender, EventArgs e)\r\n   at System.Windows.Forms.Control.OnClick(EventArgs e)\r\n   at System.Windows.Forms.Button.OnClick(EventArgs e)\r\n   at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)\r\n   at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)\r\n   at System.Windows.Forms.Application.Run(Form fm)\r\n   at MobileOrderManagement.Program.Main()\r\n"


    FaultMessage: "<s:Fault xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><faultcode xmlns:a=\"http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher\">a:InternalServiceFault</faultcode><faultstring xml:lang=\"en-US\">The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the &lt;serviceDebug&gt; configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.</faultstring></s:Fault>"


    Please help to resolve this issue.


    Thank you,


    Monday, July 11, 2011 5:50 PM
  • use WCF tracing to track the exact error.
    Monday, July 11, 2011 11:40 PM
  • Hi June,

       Thank you for the response. I could solve the issue and successfully sync only specific rows. However, I also want to filter based on another column value but this column is not the primary key like the previous one. So, will the same solution work for non-primary keys as well. Otherwise How can I filter rows based on column value which is not primary key.


    Thank you,


    Tuesday, July 12, 2011 10:02 PM
  • the filter should work with non-PK columns.
    Wednesday, July 13, 2011 1:36 AM
  • How can I add filter for non-PK columns .In my AddFilter() function we are adding condition like this:

     string myFilter = " (CT.UserId=@UserId) AND ";

    But for non-PK columns we can't use CT. to refer to that column. Please tell me how I should add the filter to refer to non-PK colunms


    Thank you,


    Monday, July 18, 2011 9:51 PM
  • you will have to join the CT with your base table and filter on the base table's column
    Tuesday, July 19, 2011 12:48 AM