DbServerSyncProvider 類別
抽取與伺服器資料庫通訊的泛型伺服器同步處理提供者,並讓同步代理程式避開此資料庫的特定實作 (Implementation)。
命名空間: 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 的類別。此類別會建立連接和命令,以便為快照集同步處理下載變更。若要在完整範例的內容中檢視這段程式碼,請參閱 HOW TO:下載資料的快照集至用戶端。
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 命名空間