Sdílet prostřednictvím


DbSyncAdapter Class

Represents a set of commands that are used to retrieve and apply data and metadata changes at the local peer database.

Namespace: Microsoft.Synchronization.Data
Assembly: Microsoft.Synchronization.Data (in microsoft.synchronization.data.dll)

Syntax

'Declaration
<SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")> _
Public Class DbSyncAdapter
'Usage
Dim instance As DbSyncAdapter
[SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")] 
public class DbSyncAdapter
[SuppressMessageAttribute(L"Microsoft.Naming", L"CA1706:ShortAcronymsShouldBeUppercase")] 
public ref class DbSyncAdapter
/** @attribute SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase") */ 
public class DbSyncAdapter
SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase") 
public class DbSyncAdapter

Remarks

DbSyncAdapter serves as a bridge between the DbSyncProvider and the peer database. Modeled after the data adapter in ADO.NET, the synchronization adapter is defined for each table that is synchronized. The synchronization adapter provides the peer synchronization provider with the specific commands that are required to interact with the peer database, such as the InsertCommand that applies inserts from one peer database to the other peer database. Because synchronization adapters use the ADO.NETDbCommand object, you can use any command structure that is supported by ADO.NET. This includes inline Transact-SQL, stored procedures, views, functions, and so on. The commands only require a single result that defines the structure and data to be transferred and applied.

Example

The following code examples create a SyncAdapter object for the Customer table, specify that the CustomerId column should be used to identify each row in the table, and specify the command for the SelectIncrementalChangesCommand property. The stored procedure that is called is defined in Setup Scripts for Database Provider How-to Topics. For more information about adapter commands and to view this code in the context of a complete example, see How to: Provision a Server Database for Collaborative Synchronization (Non-SQL Server).

DbSyncAdapter adapterCustomer = new DbSyncAdapter("Customer");


//Specify the primary key, which Sync Framework uses
//to identify each row during synchronization.
adapterCustomer.RowIdColumns.Add("CustomerId");
SqlCommand chgsCustomerCmd = new SqlCommand();
chgsCustomerCmd.CommandType = CommandType.StoredProcedure;
chgsCustomerCmd.CommandText = "Sync.sp_Customer_SelectChanges";
chgsCustomerCmd.Parameters.Add("@" + DbSyncSession.SyncMetadataOnly, SqlDbType.Int);
chgsCustomerCmd.Parameters.Add("@" + DbSyncSession.SyncMinTimestamp, SqlDbType.BigInt);
chgsCustomerCmd.Parameters.Add("@" + DbSyncSession.SyncScopeLocalId, SqlDbType.Int);
chgsCustomerCmd.Parameters.Add("@" + DbSyncSession.SyncInitialize, SqlDbType.Int);

adapterCustomer.SelectIncrementalChangesCommand = chgsCustomerCmd;
Dim adapterCustomer As New DbSyncAdapter("Customer")

'Specify the primary key, which Sync Framework uses
'to identify each row during synchronization.
adapterCustomer.RowIdColumns.Add("CustomerId")
Dim chgsCustomerCmd As New SqlCommand()

With chgsCustomerCmd
    .CommandType = CommandType.StoredProcedure
    .CommandText = "Sync.sp_Customer_SelectChanges"
    .Parameters.Add("@" + DbSyncSession.SyncMetadataOnly, SqlDbType.Int)
    .Parameters.Add("@" + DbSyncSession.SyncMinTimestamp, SqlDbType.BigInt)
    .Parameters.Add("@" + DbSyncSession.SyncScopeLocalId, SqlDbType.Int)
    .Parameters.Add("@" + DbSyncSession.SyncInitialize, SqlDbType.Int)
End With

adapterCustomer.SelectIncrementalChangesCommand = chgsCustomerCmd

Inheritance Hierarchy

System.Object
  Microsoft.Synchronization.Data.DbSyncAdapter

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

DbSyncAdapter Members
Microsoft.Synchronization.Data Namespace