Share via


Classe SqlSyncProvider

Representa um provedor de sincronização que se comunica com um banco de dados do SQL Server e protege outros componentes do Sync Framework da implementação específica do banco de dados.

Esta API não é compatível com CLS. 

Namespace:  Microsoft.Synchronization.Data.SqlServer
Assembly:  Microsoft.Synchronization.Data.SqlServer (em Microsoft.Synchronization.Data.SqlServer.dll)

Sintaxe

'Declaração
<CLSCompliantAttribute(False)> _
Public Class SqlSyncProvider _
    Inherits RelationalSyncProvider
'Uso
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

Comentários

As principais atividades de um provedor de sincronização são as seguintes:

  • Armazena informações sobre as tabelas no par que estão habilitadas para sincronização.

  • Permite que os aplicativos recuperem alterações ocorridas no banco de dados desde a última sincronização.

  • Aplica alterações incrementais no banco de dados.

  • Detecta alterações conflitantes.

Exemplos

O exemplo de código a seguir instancia provedores para três sessões de sincronização diferentes: entre o servidor e o cliente do SQL Server; entre o cliente do SQL Server e um dos clientes do SQL Server Compact e entre o servidor e o outro cliente do SQL Server Compact. Um dos clientes do SQL Server Compact é inicializado usando um instantâneo do banco de dados. Para exibir esse código no contexto de um exemplo completo, consulte Como configurar e executar a sincronização de bancos de dados (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")

Hierarquia de herança

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

Segurança de thread

Quaisquer membros static (Shared no Visual Basic) públicos deste tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.

Consulte também

Referência

Membros SqlSyncProvider

Namespace Microsoft.Synchronization.Data.SqlServer