共用方式為


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 物件,其中包含應該用來產生快照集之資料庫的連接。

例外

例外狀況 條件
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 與伺服器資料庫。若要在完整範例的內容中檢視這段程式碼,請參閱 HOW TO:設定及執行資料庫同步處理 (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類別

SqlCeSyncStoreSnapshotInitialization 成員

Microsoft.Synchronization.Data.SqlServerCe 命名空間