Partager via


Classe DbServerSyncProvider

Extrait un fournisseur de synchronisation serveur générique qui communique avec la base de données serveur et qui protège l'agent de synchronisation contre l'implémentation spécifique de cette base de données.

Espace de noms :  Microsoft.Synchronization.Data.Server
Assembly :  Microsoft.Synchronization.Data.Server (dans Microsoft.Synchronization.Data.Server.dll)

Syntaxe

'Déclaration
Public Class DbServerSyncProvider _
    Inherits ServerSyncProvider _
    Implements IDisposable
'Utilisation
Dim instance As DbServerSyncProvider
public class DbServerSyncProvider : ServerSyncProvider, 
    IDisposable
public ref class DbServerSyncProvider : public ServerSyncProvider, 
    IDisposable
type DbServerSyncProvider =  
    class
        inherit ServerSyncProvider
        interface IDisposable
    end
public class DbServerSyncProvider extends ServerSyncProvider implements IDisposable

Notes

Les principales activités du fournisseur de synchronisation serveur sont les suivantes :

  • Stocke des informations sur les tables du serveur qui sont activées pour la synchronisation.

  • Permet aux applications de récupérer les modifications intervenues dans la base de données serveur depuis la dernière synchronisation.

  • Applique les modifications incrémentielles à la base de données serveur.

  • Détecte les modifications conflictuelles.

Exemples

L'exemple de code suivant crée une classe qui dérive de DbServerSyncProvider. La classe crée une connexion et des commandes pour télécharger les modifications pour la synchronisation par instantané. Pour afficher ce code dans le contexte d'un exemple complet, consultez Procédure : télécharger un instantané des données sur un client.

public class SampleServerSyncProvider : DbServerSyncProvider
{
    public SampleServerSyncProvider()
    {
        //Create a connection to the sample server database.
        Utility util = new Utility();
        SqlConnection serverConn = new SqlConnection(Utility.ConnStr_DbServerSync);
        this.Connection = serverConn;

        //Create a SyncAdapter for each table, and then define
        //the command to select rows from the table. With the Snapshot
        //option, you do not download incremental changes. However,
        //you still use the SelectIncrementalInsertsCommand to select
        //the rows to download for each snapshot. The commands include
        //only those columns that you want on the client.

        //Customer table.
        SyncAdapter customerSyncAdapter = new SyncAdapter("Customer");
        SqlCommand customerIncrInserts = new SqlCommand();
        customerIncrInserts.CommandText = 
            "SELECT CustomerId, CustomerName, SalesPerson, CustomerType " +
            "FROM Sales.Customer";
        customerIncrInserts.Connection = serverConn;
        customerSyncAdapter.SelectIncrementalInsertsCommand = customerIncrInserts;
        this.SyncAdapters.Add(customerSyncAdapter);

        //OrderHeader table.
        SyncAdapter orderHeaderSyncAdapter = new SyncAdapter("OrderHeader");
        SqlCommand orderHeaderIncrInserts = new SqlCommand();
        orderHeaderIncrInserts.CommandText = 
            "SELECT OrderId, CustomerId, OrderDate, OrderStatus " +
            "FROM Sales.OrderHeader";
        orderHeaderIncrInserts.Connection = serverConn;
        orderHeaderSyncAdapter.SelectIncrementalInsertsCommand = orderHeaderIncrInserts;
        this.SyncAdapters.Add(orderHeaderSyncAdapter);

        //OrderDetail table.
        SyncAdapter orderDetailSyncAdapter = new SyncAdapter("OrderDetail");
        SqlCommand orderDetailIncrInserts = new SqlCommand();            
        orderDetailIncrInserts.CommandText = 
            "SELECT OrderDetailId, OrderId, Product, Quantity " +
            "FROM Sales.OrderDetail";
        orderDetailIncrInserts.Connection = serverConn;
        orderDetailSyncAdapter.SelectIncrementalInsertsCommand = orderDetailIncrInserts;
        this.SyncAdapters.Add(orderDetailSyncAdapter);
    }
}
Public Class SampleServerSyncProvider
    Inherits DbServerSyncProvider

    Public Sub New()
        'Create a connection to the sample server database.
        Dim util As New Utility()
        Dim serverConn As New SqlConnection(Utility.ConnStr_DbServerSync)
        Me.Connection = serverConn

        'Create a SyncAdapter for each table, and then define
        'the command to select rows from the table. With the Snapshot
        'option, you do not download incremental changes. However,
        'you still use the SelectIncrementalInsertsCommand to select
        'the rows to download for each snapshot. The commands include
        'only those columns that you want on the client.
        'Customer table.
        Dim customerSyncAdapter As New SyncAdapter("Customer")
        Dim customerIncrInserts As New SqlCommand()
        customerIncrInserts.CommandText = _
            "SELECT CustomerId, CustomerName, SalesPerson, CustomerType " _
          & "FROM Sales.Customer"
        customerIncrInserts.Connection = serverConn
        customerSyncAdapter.SelectIncrementalInsertsCommand = customerIncrInserts
        Me.SyncAdapters.Add(customerSyncAdapter)

        'OrderHeader table.
        Dim orderHeaderSyncAdapter As New SyncAdapter("OrderHeader")
        Dim orderHeaderIncrInserts As New SqlCommand()
        orderHeaderIncrInserts.CommandText = _
            "SELECT OrderId, CustomerId, OrderDate, OrderStatus " _
          & "FROM Sales.OrderHeader"
        orderHeaderIncrInserts.Connection = serverConn
        orderHeaderSyncAdapter.SelectIncrementalInsertsCommand = orderHeaderIncrInserts
        Me.SyncAdapters.Add(orderHeaderSyncAdapter)

        'OrderDetail table.
        Dim orderDetailSyncAdapter As New SyncAdapter("OrderDetail")
        Dim orderDetailIncrInserts As New SqlCommand()
        orderDetailIncrInserts.CommandText = _
            "SELECT OrderDetailId, OrderId, Product, Quantity " _
          & "FROM Sales.OrderDetail"
        orderDetailIncrInserts.Connection = serverConn
        orderDetailSyncAdapter.SelectIncrementalInsertsCommand = orderDetailIncrInserts
        Me.SyncAdapters.Add(orderDetailSyncAdapter)

    End Sub 'New
End Class 'SampleServerSyncProvider

Hiérarchie d'héritage

System. . :: . .Object
  Microsoft.Synchronization. . :: . .SyncProvider
    Microsoft.Synchronization.Data. . :: . .ServerSyncProvider
      Microsoft.Synchronization.Data.Server..::..DbServerSyncProvider

Sécurité des threads

Tous les membres publics static (Shared dans Visual Basic) de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.

Voir aussi

Référence

Membres DbServerSyncProvider

Espace de noms Microsoft.Synchronization.Data.Server