How To: Provision for Synchronization Using Snapshot Initialization

This topic describes how to provision a SQL Server Compact database efficiently by using a snapshot of a database that is already initialized. The examples in this topic focus on the following Sync Framework classes:



For more information about how to run the sample code, see "Example Applications in the How to Topics" in Synchronizing SQL Server and SQL Server Compact.

Provisioning the Clients

If you are provisioning more than one SQL Server Compact database for synchronization, you can reduce the total time required for initialization by using a database snapshot. A snapshot is a specially-prepared SQL Server Compact database that contains table schema, data (optional), and change-tracking infrastructure. After you have fully initialized one SQL Server Compact database, you create a snapshot that you copy to subsequent SQL Server Compact databases that you want to synchronize. The process of applying the snapshot to the database is faster than fully initializing it.

During the first synchronization session for a client, client-specific metadata is updated, and any changes that occurred since the snapshot was created are downloaded to the client database.


Snapshots should be generated only when there is no activity in the SQL Server Compact database. Concurrent operations of any type are not supported during snapshot generation.

The code examples shown here demonstrate creating and initializing a SQL Server Compact database, and then using a snapshot of that database to initialize a second database.

The following code example retrieves scope information from the server and uses the base table and change-tracking schemas that are retrieved to provision a SQL Server Compact client database.

The following code example generates a snapshot named SyncSampleClient2.sdf from the SyncSampleClient1.sdf database. The code then synchronizes SyncSampleClient2.sdf with the server database. The client database is initialized during the synchronization, but you also could use InitializeSnapshot explicitly to initialize the database.


The following complete code example includes the code examples that are described earlier and additional code to configure and clean up the databases. The example requires the Utility class that is available in Utility Class for Database Provider How-to Topics.