共用方式為


SqlSyncProvider 類別

表示與 SQL Server 資料庫通訊並讓其他 Sync Framework 元件避開資料庫之特定實作的同步處理提供者。

此 API 不符合 CLS 標準。 

命名空間:  Microsoft.Synchronization.Data.SqlServer
組件:  Microsoft.Synchronization.Data.SqlServer (在 Microsoft.Synchronization.Data.SqlServer.dll 中)

語法

'宣告
<CLSCompliantAttribute(False)> _
Public Class SqlSyncProvider _
    Inherits RelationalSyncProvider
'用途
Dim instance As SqlSyncProvider
[CLSCompliantAttribute(false)]
public class SqlSyncProvider : RelationalSyncProvider
[CLSCompliantAttribute(false)]
public ref class SqlSyncProvider : public RelationalSyncProvider
[<CLSCompliantAttribute(false)>]
type SqlSyncProvider =  
    class
        inherit RelationalSyncProvider
    end
public class SqlSyncProvider extends RelationalSyncProvider

備註

同步處理提供者的主要活動如下所示:

  • 儲存有關在啟用同步處理之對等項目上的資料表資訊。

  • 讓應用程式能擷取自從上一次同步處理後發生在資料庫中的變更。

  • 套用累加變更至資料庫。

  • 偵測衝突變更。

範例

下列程式碼範例會具現化三個不同同步處理工作階段的提供者:在伺服器與 SQL Server 用戶端之間、在 SQL Server 用戶端與其中一個 SQL Server Compact 用戶端之間,以及在伺服器與其他 SQL Server Compact 用戶端之間。 其中一個 SQL Server Compact 用戶端是使用資料庫快照集來初始化。若要在完整範例的內容中檢視這段程式碼,請參閱 HOW TO:設定及執行資料庫同步處理 (SQL Server)

SampleSyncOrchestrator syncOrchestrator;
SyncOperationStatistics syncStats;

// Data is downloaded from the server to the SQL Server client.
syncOrchestrator = new SampleSyncOrchestrator(
    new SqlSyncProvider("filtered_customer", clientSqlConn, null, "Sync"),
    new SqlSyncProvider("filtered_customer", serverConn, null, "Sync")
    );
syncStats = syncOrchestrator.Synchronize();
syncOrchestrator.DisplayStats(syncStats, "initial");

// Data is downloaded from the SQL Server client to the 
// first SQL Server Compact client.
syncOrchestrator = new SampleSyncOrchestrator(
    new SqlCeSyncProvider("filtered_customer", clientSqlCe1Conn, "Sync"),
    new SqlSyncProvider("filtered_customer", clientSqlConn, null, "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.
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");
Dim syncOrchestrator As SampleSyncOrchestrator
Dim syncStats As SyncOperationStatistics

' Data is downloaded from the server to the SQL Server client. 
syncOrchestrator = New SampleSyncOrchestrator( _
    New SqlSyncProvider("filtered_customer", clientSqlConn, Nothing, "Sync"), _
    New SqlSyncProvider("filtered_customer", serverConn, Nothing, "Sync"))
syncStats = syncOrchestrator.Synchronize()
syncOrchestrator.DisplayStats(syncStats, "initial")

' Data is downloaded from the SQL Server client to the 
' first SQL Server Compact client. 
syncOrchestrator = New SampleSyncOrchestrator( _
    New SqlCeSyncProvider("filtered_customer", clientSqlCe1Conn, "Sync"), _
    New SqlSyncProvider("filtered_customer", clientSqlConn, Nothing, "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")

繼承階層

System. . :: . .Object
  Microsoft.Synchronization. . :: . .SyncProvider
    Microsoft.Synchronization. . :: . .KnowledgeSyncProvider
      Microsoft.Synchronization.Data. . :: . .RelationalSyncProvider
        Microsoft.Synchronization.Data.SqlServer..::..SqlSyncProvider

執行緒安全性

這個類型的任何公用static (在 Visual Basic 中為 Shared) 成員都是安全執行緒。不保證任何執行個體成員都可以是安全執行緒。

請參閱

參考

SqlSyncProvider 成員

Microsoft.Synchronization.Data.SqlServer 命名空間