DbSyncAdapter Class

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

Inheritance Hierarchy

System.Object
  Microsoft.Synchronization.Data.DbSyncAdapter

Namespace:  Microsoft.Synchronization.Data
Assembly:  Microsoft.Synchronization.Data (in Microsoft.Synchronization.Data.dll)

Syntax

'Declaration
Public Class DbSyncAdapter
'Usage
Dim instance As DbSyncAdapter
public class DbSyncAdapter
public ref class DbSyncAdapter
type DbSyncAdapter =  class end
public class DbSyncAdapter

The DbSyncAdapter type exposes the following members.

Constructors

  Name Description
Public method DbSyncAdapter() Initializes a new instance of the DbSyncAdapter class by using default values.
Public method DbSyncAdapter(String) Initializes a new instance of the DbSyncAdapter class by using a table name parameter.
Public method DbSyncAdapter(String, String) Initializes a new instance of the DbSyncAdapter class by using local and remote table name parameters.

Top

Properties

  Name Description
Public property ColumnMappings Gets a collection of DbSyncColumnMapping objects for the table. These objects map columns in a local table to the corresponding columns in a remote table.
Public property DeleteCommand Gets or sets the query or stored procedure that is used to delete data from the base table.
Public property DeleteMetadataCommand Gets or sets the query or stored procedure that is used to delete metadata from the metadata table.
Public property Description Gets or sets a description for the synchronization adapter.
Public property InsertCommand Gets or sets the query or stored procedure that is used to insert data into the base table.
Public property InsertMetadataCommand Gets or sets the query or stored procedure that is used to insert metadata into the metadata table.
Public property RemoteTableName Gets or sets the name of the table at the remote peer for which to create the DbSyncAdapter object.
Public property RowIdColumns Gets a collection of the names of the columns that make up the unique ID for each row in the table.
Public property SelectIncrementalChangesCommand Gets or sets the query or stored procedure that is used to select incremental changes from the local database.
Public property SelectMetadataForCleanupCommand Gets or sets the query or stored procedure that is used to cleanup rows in metadata tables.
Public property SelectRowCommand Gets or sets the query or stored procedure that is used to select a specific row given an ID for that row.
Public property TableName Gets or sets the name of the table at the peer for which to create the DbSyncAdapter object.
Public property UpdateCommand Gets or sets the query or stored procedure that is used to update data in the base table.
Public property UpdateMetadataCommand Gets or sets the query or stored procedure that is used to update metadata in the metadata table.

Top

Methods

  Name Description
Protected methodStatic member DisposeCommand Disposes the specified command object that implements the IDisposable interface.
Public method Equals (Inherited from Object.)
Protected method Finalize (Inherited from Object.)
Public method GetHashCode (Inherited from Object.)
Public method GetType (Inherited from Object.)
Protected method MemberwiseClone (Inherited from Object.)
Public method ToString Returns a string that represents the DbSyncAdapter object. (Overrides Object.ToString().)

Top

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.NET DbCommand 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.

Examples

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

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

Microsoft.Synchronization.Data Namespace