views:

225

answers:

1

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.

+1  A: 

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
nj
Thank you! I'll try this a bit later, because now have some other task. Sure will accept the answer if it helps, but i understood the point you gave, so thanks.
nihi_l_ist
Good, just let me know if you want me to clarify something.
nj