0x49D1
0x49D1

Reputation: 8704

How to split synchronization process in sync framework

I'm using sync framework to synchronize sql server 2008 database with sqlCE on mobile device. Everything looks fine besides some problems. One of them is:
If i want to sync 1000 or more rows, i get OutOfMemory Exception on mobile device(tho the sync completes well, because after it i check the data of some rows and it looks synced). I thought that maybe too large xmls are rotating between mobile device and server(for 100 rows evrth works just fine)...Thats why i asked about how to split the sent data. But maybe im wrong. I didn't found any resources on this, so i dont exactly know WHAT can eat so much memory to add just 60Kb to the compact database.

Upvotes: 0

Views: 1082

Answers (1)

nj.
nj.

Reputation: 756

You'll need to implement some sort of batching.

A quite naive version of it is shown on here: http://msdn.microsoft.com/en-us/library/bb902828.aspx.

I've seen that you're intrested in some filtring. If this will filter out some, or rather alot, of rows I would recommend to write your own batch logic. The one we're currently using sets the @sync_new_received_anchor to the anchor of the @sync_batch_size:th row to be synced.

In a quite simplified way the logic looks like this:

SELECT @sync_new_received_anchor = MAX(ThisBatch.ChangeVersion) 
    FROM (SELECT TOP (@sync_batch_size) CT.SYS_CHANGE_VERSION AS ChangeVersion 
        FROM TabletoSync
             INNER JOIN CHANGETABLE(CHANGES [TabletoSync],
                                @sync_last_received_anchor) AS CT 
            ON TabletoSync. TabletoSyncID = CT. TabletoSyncID 
            WHERE TabletoSync.FilterColumn = @ToClient
            ORDER BY CT.SYS_CHANGE_VERSION ASC) AS ThisBatch

Upvotes: 1

Related Questions