DbServerSyncProvider Clase

Abstrae un proveedor genérico de sincronización del servidor que comunica con la base de datos servidor y aísla el agente de sincronización de la implementación específica de esa base de datos.

Espacio de nombres: Microsoft.Synchronization.Data.Server
Ensamblado: Microsoft.Synchronization.Data.Server (en microsoft.synchronization.data.server.dll)

Sintaxis

'Declaración
<SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")> _
Public Class DbServerSyncProvider
    Inherits ServerSyncProvider
    Implements IDisposable
'Uso
Dim instance As DbServerSyncProvider
[SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")] 
public class DbServerSyncProvider : ServerSyncProvider, IDisposable
[SuppressMessageAttribute(L"Microsoft.Naming", L"CA1706:ShortAcronymsShouldBeUppercase")] 
public ref class DbServerSyncProvider : public ServerSyncProvider, IDisposable
/** @attribute SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase") */ 
public class DbServerSyncProvider extends ServerSyncProvider implements IDisposable
SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase") 
public class DbServerSyncProvider extends ServerSyncProvider implements IDisposable

Notas

Las actividades principales del proveedor de sincronización del servidor son:

  • Almacena información de las tablas del servidor habilitadas para sincronización.

  • Permite a las aplicaciones recuperar los cambios producidos en la base de datos servidor desde la última sincronización.

  • Aplica los cambios incrementales a la base de datos servidor.

  • Detecta los cambios en conflicto.

Ejemplo

El ejemplo de código siguiente crea una clase derivada de DbServerSyncProvider. La clase crea una conexión y comandos para descargar cambios a fin de realizar sincronización simultánea. Para consultar este código en el contexto de un ejemplo completo, vea Cómo descargar una instantánea de datos en un cliente.

public class SampleServerSyncProvider : DbServerSyncProvider
{
    public SampleServerSyncProvider()
    {
        //Create a connection to the sample server database.
        Utility util = new Utility();
        SqlConnection serverConn = new SqlConnection(util.ServerConnString);
        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(util.ServerConnString)
        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

Jerarquía de herencia

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

Seguridad para subprocesos

Todos los miembros (Compartidos en Visual Basic) de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.

Vea también

Referencia

DbServerSyncProvider Miembros
Microsoft.Synchronization.Data.Server Espacio de nombres