產生可用來初始化其他 SQL Server Compact 資料庫以便進行同步處理的現有 SQL Server Compact 資料庫檔案快照集。
命名空間: Microsoft.Synchronization.Data.SqlServerCe
組件: Microsoft.Synchronization.Data.SqlServerCe (在 microsoft.synchronization.data.sqlserverce.dll)
語法
'宣告
<SuppressMessageAttribute("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes")> _
<SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")> _
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)
[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
)
參數
- sourceConnection
SqlCeConnection 物件,其中包含應該用來產生快照集之資料庫的連接。
- destinationDatabasePath
應該寫入快照集的檔案路徑。
備註
快照集初始化的用意是要減少初始化用戶端資料庫所需的時間。當已經使用完整初始化來初始化一個用戶端資料庫之後,後續的資料庫可以使用第一個用戶端資料庫的「快照集」來初始化。快照集是特別準備的 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 命名空間