GenerateSnapshot 方法
获取可用于初始化其他 SQL Server Compact 数据库以便进行同步的现有 SQL Server Compact 数据库文件的快照。
命名空间: Microsoft.Synchronization.Data.SqlServerCe
程序集: Microsoft.Synchronization.Data.SqlServerCe(在 Microsoft.Synchronization.Data.SqlServerCe.dll 中)
语法
声明
Public Sub GenerateSnapshot ( _
sourceConnection As SqlCeConnection, _
destinationDatabasePath As String _
)
用法
Dim instance As SqlCeSyncStoreSnapshotInitialization
Dim sourceConnection As SqlCeConnection
Dim destinationDatabasePath As String
instance.GenerateSnapshot(sourceConnection, _
destinationDatabasePath)
public void GenerateSnapshot(
SqlCeConnection sourceConnection,
string destinationDatabasePath
)
public:
void GenerateSnapshot(
SqlCeConnection^ sourceConnection,
String^ destinationDatabasePath
)
member GenerateSnapshot :
sourceConnection:SqlCeConnection *
destinationDatabasePath:string -> unit
public function GenerateSnapshot(
sourceConnection : SqlCeConnection,
destinationDatabasePath : String
)
参数
- sourceConnection
类型:SqlCeConnection
一个 SqlCeConnection 对象,它包含与应从其生成快照的数据库的连接。
- destinationDatabasePath
类型:System. . :: . .String
快照应写入的文件路径。
异常
异常 | 条件 |
---|---|
ArgumentNullException | sourceConnection 为 null Nothing nullptr unit null 引用(在 Visual Basic 中为 Nothing) 。 |
ArgumentException | destinationDatabasePath 为 null Nothing nullptr unit null 引用(在 Visual Basic 中为 Nothing) 或空, destinationDatabasePath 不是文件, — 或者 — destinationDatabasePath 是 UNC 路径。 |
DbSyncException | 无法初始化快照。 |
注释
快照初始化旨在减少初始化客户端数据库所需的时间。在通过使用完全初始化来初始化一个客户端数据库后,可以通过使用这个第一个客户端数据库的“快照”初始化后续数据库。快照是专门准备的 SQL Server Compact 数据库,包含表架构、数据(可选)和变更跟踪基础结构。将此快照复制到要求它的每个客户端。在客户端的第一个同步会话期间,将更新特定于客户端的元数据,并且自创建快照后发生的任何变更都将下载到客户端数据库。
重要提示 |
---|
只有在 SQL Server Compact 数据库中没有任何活动时,才应生成快照。在快照生成期间不支持任何类型的并发操作。 |
示例
下面的代码示例从 SyncSampleClient1.sdf 数据库生成一个名为 SyncSampleClient2.sdf 的快照。该代码然后将 SyncSampleClient2.sdf 与服务器数据库同步。若要在完整示例上下文中查看此代码,请参见如何配置和执行数据库同步 (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")
请参阅
参考
SqlCeSyncStoreSnapshotInitialization类