none
Seeking sample code for device to server sync RRS feed

  • Question

  • Is there any sample code which shows a device storing metadata and it's (partial participant) database provider running on a PC?

    Thanks,

    Windflower

    Wednesday, April 7, 2010 11:33 PM

Answers

  • If you're using SQLCeSyncProvider, provisioning will create a table with suffix _tracking for each table you sync. Likewise, you will find two additional tables scope_config and scope_info, the former contains the sync scope definition (tables, columns, etc... involved) and latter contains the sync knowledge (what was sync, etc...)

    you'll find that tables in the sync also has two hidden columns: _sysChangeTxBsn and _sysInsertTxBsn. In addition, there's 3 hidden tables as well that's added: __sysOCSDeletedRows, __sysOCSTrackedObjects, __sysTxCommitSequence.

    you will find also that an SDF has to be initially provisioned using a sync scope from another provisioned scope (e.g., SQLSyncProvider). However, once you have provisioned an SDF, you can generate snapshots of the SDF (SqlCeSyncStoreSnapshotInitialization.GenerateSnapshot).

    for a start, you may want to look at the SharingAppDemo-CEProviderEndToEnd sample which gets installed as part of the SDK. The sample shows initializing an SDF from a SQLSyncProvider, sync between SQLSyncProvider to SQLCESyncProvider, initializing another SDF from an existing SDF and synchronizing SDF to SDF.

    • Marked as answer by wwaters Monday, April 12, 2010 10:23 PM
    Saturday, April 10, 2010 12:58 AM
    Moderator

All replies

  • Windflower,

    Could you provide more info about your scenario and what databases are involved?

    Thanks,

    Phil

    Friday, April 9, 2010 6:23 PM
    Answerer
  • I have several Windows Mobile devices with SQL Compact databases. We previously had an SQL Server Express database on a PC which was a publisher for Merge Replication. Now we are switching to an SQL Compact database on the PC as well. In parallel with that we will move to using the Sync Framework because merge replication will no longer work. In addition, the sync framework will give us the ability to do conflict resolution when the same row has been updated in more than one database. Devices will be synced with the PC one at a time.

    We will initialize the device databases from the laptop database, go out and do work with the devices, then  connect each device to sync collected data (upload and download) with the  laptop.

    I was considering an architecture like the first one shown in "Architecture and Classes for Collaborative Synchronization" http://msdn.microsoft.com/en-us/library/bb902829(v=SQL.105).aspx since the framework isn't supported on the device. I would implement ApplyChangesFailed to handle row conflicts using business logic.

    Two issues I'm thinking about right now are

    1) how and where the metadata get saved on the device. I'm not sure when the SqlCeSyncProvider writes the metatdata, where it stores it, or exactly what data is writes. My understanding is that the Custom Providers use the Metadata Storage classes but the standard providers have private methods and do not do the same thing as the Custom Providers.

    2)  since the web doc referenced above says "If you are synchronizing two SQL Server Compact databases by using two instances of SqlCeSyncProvider, you must use an n-tier architecture. Two-tier architectures are not supported for this scenario." , I'm sure what I should use as a provider when syncing two SQL Compact databases. One is effectively the server, even though it is a Compact database.

    Is it the case that the differences in the metadata management preclude combining standard providers with custom providers? I'd rather use the standard providers if possible anyway.

    Thanks,
    Windflower

    Friday, April 9, 2010 8:22 PM
  • If you're using SQLCeSyncProvider, provisioning will create a table with suffix _tracking for each table you sync. Likewise, you will find two additional tables scope_config and scope_info, the former contains the sync scope definition (tables, columns, etc... involved) and latter contains the sync knowledge (what was sync, etc...)

    you'll find that tables in the sync also has two hidden columns: _sysChangeTxBsn and _sysInsertTxBsn. In addition, there's 3 hidden tables as well that's added: __sysOCSDeletedRows, __sysOCSTrackedObjects, __sysTxCommitSequence.

    you will find also that an SDF has to be initially provisioned using a sync scope from another provisioned scope (e.g., SQLSyncProvider). However, once you have provisioned an SDF, you can generate snapshots of the SDF (SqlCeSyncStoreSnapshotInitialization.GenerateSnapshot).

    for a start, you may want to look at the SharingAppDemo-CEProviderEndToEnd sample which gets installed as part of the SDK. The sample shows initializing an SDF from a SQLSyncProvider, sync between SQLSyncProvider to SQLCESyncProvider, initializing another SDF from an existing SDF and synchronizing SDF to SDF.

    • Marked as answer by wwaters Monday, April 12, 2010 10:23 PM
    Saturday, April 10, 2010 12:58 AM
    Moderator
  • I've been working with the demo you referenced. I should be able to do provisioning of the sdf database at my site then bundle a provisioned sdf master database with our installer. Then I can do snapshot initialization for the device databases from that master.  That works fine.

    Is there existing code that will run on Windows Mobile and will write or help with the management of the metatdata for this scenario?

    -- Windflower

    Monday, April 12, 2010 3:29 PM
  • just lookup SqlCeSyncStoreMetadataCleanup on how to do metadata clean up.

     

     

    Monday, April 12, 2010 9:21 PM
    Moderator
  • I wasn't thinking about the Metadata cleanup but rather about updating the metadata before the sync starts. But I think it is done by the provider from the PC  at the beginning of the sync session for a device which is behaving as a partial provider. That is, I dont' update the device metadata from the device for this scenario.

    I will need to take of the cleanup as well.

    Thanks for the help.

    Monday, April 12, 2010 10:30 PM
  • yes, sync framework takes care of updating the metadata.

    cheers

    Monday, April 12, 2010 11:02 PM
    Moderator
  • btw, Microsoft SQL Server Compact 3.5 Service Pack 2 for Windows Desktop was just released.

    This exposes an API for the SQL Compact Change Tracking.

    http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=e497988a-c93a-404c-b161-3a0b323dce24

    Tuesday, April 13, 2010 9:18 AM
    Moderator
  • Very interesting. If I use change tracking, then I have to use a custom provider, correct? You can't mix standard database providers and custom providers because they handle metadata differently, correct?

    Thanks,

    Windflower

    Tuesday, April 13, 2010 1:09 PM