DbServerSyncProvider.SelectNewAnchorCommand Property

Gets or sets an IDbCommand object that contains the query or stored procedure that returns a new anchor value from the server database. The anchor defines the upper bound for the set of changes to be synchronized during the current session.

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


Public Property SelectNewAnchorCommand As IDbCommand
Dim instance As DbServerSyncProvider
Dim value As IDbCommand

value = instance.SelectNewAnchorCommand

instance.SelectNewAnchorCommand = value
public IDbCommand SelectNewAnchorCommand { get; set; }
property IDbCommand^ SelectNewAnchorCommand {
    IDbCommand^ get ();
    void set (IDbCommand^ value);
member SelectNewAnchorCommand : IDbCommand with get, set
function get SelectNewAnchorCommand () : IDbCommand
function set SelectNewAnchorCommand (value : IDbCommand)

Property Value

Type: System.Data.IDbCommand
An IDbCommand object that contains a query or stored procedure.


During the current synchronization, the new anchor command provides a new anchor value. Changes that are made after the last received anchor value and before the new received anchor value are synchronized. The new received anchor is then stored and used as the last received anchor value for the next synchronization. For more information, see the section "Determining Which Data Changes to Download to a Client" in Tracking Changes in the Server Database.


The following code example specifies a command to retrieve a new anchor value from the server. In this case, MIN_ACTIVE_ROWVERSION returns a timestamp value from a SQL Server database. (MIN_ACTIVE_ROWVERSION was introduced in SQL Server 2005 Service Pack 2.) A timestamp value is used because the tracking columns in the server database contain timestamp values. If the tracking columns contained date values, you could use a function such as GETUTCDATE() instead of MIN_ACTIVE_ROWVERSION. SyncSession contains several string constants that can be used in synchronization commands. SyncNewReceivedAnchor is one of these constants. You could also use the literal @sync\_new\_received\_anchor directly in your queries. To view this code in the context of a complete example, see Getting Started: Client and Server Synchronization.

SqlCommand selectNewAnchorCommand = new SqlCommand();
string newAnchorVariable = "@" + SyncSession.SyncNewReceivedAnchor;
selectNewAnchorCommand.CommandText = "SELECT " + newAnchorVariable + " = min_active_rowversion() - 1";
selectNewAnchorCommand.Parameters.Add(newAnchorVariable, SqlDbType.Timestamp);
selectNewAnchorCommand.Parameters[newAnchorVariable].Direction = ParameterDirection.Output;
selectNewAnchorCommand.Connection = serverConn;
this.SelectNewAnchorCommand = selectNewAnchorCommand;
Dim selectNewAnchorCommand As New SqlCommand()
Dim newAnchorVariable As String = "@" + SyncSession.SyncNewReceivedAnchor
selectNewAnchorCommand.CommandText = "SELECT " + newAnchorVariable + " = min_active_rowversion() - 1"
selectNewAnchorCommand.Parameters.Add(newAnchorVariable, SqlDbType.Timestamp)
selectNewAnchorCommand.Parameters(newAnchorVariable).Direction = ParameterDirection.Output
selectNewAnchorCommand.Connection = serverConn
Me.SelectNewAnchorCommand = selectNewAnchorCommand

See Also


DbServerSyncProvider Class

Microsoft.Synchronization.Data.Server Namespace