SqlCeSyncStoreSnapshotInitialization.GenerateSnapshot Method
Generates a snapshot of an existing SQL Server Compact database file that can be used to initialize another SQL Server Compact database for synchronization.
Namespace: Microsoft.Synchronization.Data.SqlServerCe
Assembly: Microsoft.Synchronization.Data.SqlServerCe (in microsoft.synchronization.data.sqlserverce.dll)
Syntax
'Declaration
<SuppressMessageAttribute("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")> _
<SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")> _
Public Sub GenerateSnapshot ( _
sourceConnection As SqlCeConnection, _
destinationDatabasePath As String _
)
'Usage
Dim instance As SqlCeSyncStoreSnapshotInitialization
Dim sourceConnection As SqlCeConnection
Dim destinationDatabasePath As String
instance.GenerateSnapshot(sourceConnection, destinationDatabasePath)
[SuppressMessageAttribute("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")]
[SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
public void GenerateSnapshot (
SqlCeConnection sourceConnection,
string destinationDatabasePath
)
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1031:DoNotCatchGeneralExceptionTypes")]
[SuppressMessageAttribute(L"Microsoft.Design", L"CA1011:ConsiderPassingBaseTypesAsParameters")]
public:
void GenerateSnapshot (
SqlCeConnection^ sourceConnection,
String^ destinationDatabasePath
)
/** @attribute SuppressMessageAttribute("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes") */
/** @attribute SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters") */
public void GenerateSnapshot (
SqlCeConnection sourceConnection,
String destinationDatabasePath
)
SuppressMessageAttribute("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")
SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")
public function GenerateSnapshot (
sourceConnection : SqlCeConnection,
destinationDatabasePath : String
)
Parameters
- sourceConnection
A SqlCeConnection object that contains a connection to the database from which the snapshot should be generated.
- destinationDatabasePath
The file path to which the snapshot should be written.
Remarks
Snapshot initialization is designed to reduce the time required to initialize a client database. After one client database has been initialized by using full initialization, subsequent databases can be initialized by using a snapshot of this first client database. A snapshot is a specially-prepared SQL Server Compact database that contains table schema, data (optional), and change-tracking infrastructure. Copy this snapshot to each client that requires 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.
Important
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.
Example
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. To view this code in the context of a complete example, see How to: Configure and Execute Collaborative Synchronization (SQL Server).
// Create a snapshot from the SQL Server Compact database, which will be used to
// initialize a second Compact database. Again, this database could be provisioned
// by retrieving scope information from another database, but we want to
// demonstrate the use of snapshots, which provide a convenient deployment
// mechanism for Compact databases.
SqlCeSyncStoreSnapshotInitialization syncStoreSnapshot = new SqlCeSyncStoreSnapshotInitialization("Sync");
syncStoreSnapshot.GenerateSnapshot(clientSqlCe1Conn, "SyncSampleClient2.sdf");
// The new SQL Server Compact client synchronizes with the server, but
// no data is downloaded because the snapshot already contains
// all of the data from the first Compact database.
syncOrchestrator = new SampleSyncOrchestrator(
new SqlSyncProvider("filtered_customer", serverConn, null, "Sync"),
new SqlCeSyncProvider("filtered_customer", clientSqlCe2Conn, "Sync")
);
syncStats = syncOrchestrator.Synchronize();
syncOrchestrator.DisplayStats(syncStats, "initial");
' Create a snapshot from the SQL Server Compact database, which will be used to
' initialize a second Compact database. Again, this database could be provisioned
' by retrieving scope information from another database, but we want to
' demonstrate the use of snapshots, which provide a convenient deployment
' mechanism for Compact databases.
Dim syncStoreSnapshot As New SqlCeSyncStoreSnapshotInitialization("Sync")
syncStoreSnapshot.GenerateSnapshot(clientSqlCe1Conn, "SyncSampleClient2.sdf")
' The new SQL Server Compact client synchronizes with the server, but
' no data is downloaded because the snapshot already contains
' all of the data from the first Compact database.
syncOrchestrator = New SampleSyncOrchestrator( _
New SqlSyncProvider("filtered_customer", serverConn, Nothing, "Sync"), _
New SqlCeSyncProvider("filtered_customer", clientSqlCe2Conn, "Sync"))
syncStats = syncOrchestrator.Synchronize()
syncOrchestrator.DisplayStats(syncStats, "initial")
See Also
Reference
SqlCeSyncStoreSnapshotInitialization Class
SqlCeSyncStoreSnapshotInitialization Members
Microsoft.Synchronization.Data.SqlServerCe Namespace