DbServerSyncProvider 클래스
서버 데이터베이스와 통신하는 일반 서버 동기화 공급자를 추상화하고 특정 데이터베이스 구현으로부터 동기화 에이전트를 보호합니다.
네임스페이스: Microsoft.Synchronization.Data.Server
어셈블리: microsoft.synchronization.data.server.dll의 Microsoft.Synchronization.Data.Server
구문
‘선언
<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
스레드로부터의 안전성
이 유형의 모든 public static(Visual Basic의 경우 Shared ) 멤버는 스레드로부터 안전합니다. 인스턴스 멤버는 스레드로부터의 안전성이 보장되지 않습니다.
참고 항목
참조
DbServerSyncProvider 멤버
Microsoft.Synchronization.Data.Server 네임스페이스