locked
Can a client determine if it needs to sync? RRS feed

  • Question

  • I was wondering if there some means by which a client could determine if there are changes in a particular table on the server that it has yet to sync.  We're using SQL Server 2008 with change tracking enabled on the server and SQL Server Compact edition on a windows mobile device. 

    I was hoping there would be a way to do this via Sync Framework calls.  I was thinking of somehow constructing or getting a SyncAnchor from the server and comparing that to the SyncAnchor you can get from the ClientSyncProvider. GetTableReceivedAnchor(tablename) method.  The problem is it's not entirely obvious to me how you go about getting the server's SyncAnchor.

    Mick Lang
    • Moved by Hengzhe Li Friday, April 22, 2011 3:22 AM (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Monday, April 27, 2009 4:58 AM

Answers

  • Hi Mick,
    An accurate check is expensive. A quick check is to compare the table level anchor on client side with the value returned by CHANGE_TRACKING_CURRENT_VERSION() on the server database. This value is incremented for every change database wide so it is not accurate. To know for sure whether there are changes or not for a particular table you will have to essentially run the query that sync runs to get the changes but do a exists or count on it instead of bringing down the resultset.

    Sync query looks something like this:

     

    SELECT <columns> FROM dbo.t1

     

    JOIN CHANGETABLE(CHANGES dbo.t1, @sync_last_received_anchor) CT

     

    ON CT.[c1] = dbo.t1.[c1]  -- primary keys

     

    WHERE (CT.SYS_CHANGE_CONTEXT IS NULL OR

    CT

    .SYS_CHANGE_CONTEXT <> @sync_client_id_binary);

    thanks
    Sudarshan


    Development Lead , Microsoft
    • Marked as answer by Mick Lang Thursday, April 30, 2009 6:15 AM
    Wednesday, April 29, 2009 8:54 PM
    Moderator