DbServerSyncProvider 类

对与服务器数据库通信的泛型服务器同步提供程序进行抽象化并将同步代理与数据库的特定实现屏蔽开来。

命名空间: Microsoft.Synchronization.Data.Server
程序集: Microsoft.Synchronization.Data.Server(在 microsoft.synchronization.data.server.dll 中)

语法

声明
<SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")> _
Public Class DbServerSyncProvider
    Inherits ServerSyncProvider
    Implements IDisposable
用法
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

备注

服务器同步提供程序的主要活动如下所示:

  • 存储与服务器上支持同步的表有关的信息。

  • 使应用程序能够检索自上次同步以来在服务器数据库中发生的变更。

  • 将增量变更应用于服务器数据库。

  • 检测发生冲突的变更。

示例

下面的代码示例创建一个派生自 DbServerSyncProvider 的类。该类创建一个连接和若干命令以下载快照同步的变更。若要在完整示例上下文中查看此代码,请参见如何将数据快照下载到客户端

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

继承层次结构

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

线程安全

此类型的所有公共静态(在 Visual Basic 中共享 )成员都是线程安全的。不保证任何实例成员的线程安全。

请参阅

参考

DbServerSyncProvider 成员
Microsoft.Synchronization.Data.Server 命名空间