SelectNewTimestampCommand 属性

获取或设置一个 IDbCommand 对象,该对象包含从对等数据库返回新时间戳值的查询或存储过程。时间戳定义要在当前会话期间同步的变更集的上限。

命名空间:  Microsoft.Synchronization.Data
程序集:  Microsoft.Synchronization.Data(在 Microsoft.Synchronization.Data.dll 中)

语法

声明
Public Overridable Property SelectNewTimestampCommand As IDbCommand
    Get
    Set
用法
Dim instance As DbSyncProvider
Dim value As IDbCommand

value = instance.SelectNewTimestampCommand

instance.SelectNewTimestampCommand = value
public virtual IDbCommand SelectNewTimestampCommand { get; set; }
public:
virtual property IDbCommand^ SelectNewTimestampCommand {
    IDbCommand^ get ();
    void set (IDbCommand^ value);
}
abstract SelectNewTimestampCommand : IDbCommand with get, set
override SelectNewTimestampCommand : IDbCommand with get, set
function get SelectNewTimestampCommand () : IDbCommand
function set SelectNewTimestampCommand (value : IDbCommand)

属性值

类型:System.Data. . :: . .IDbCommand
包含查询或存储过程的 IDbCommand 对象。

注释

为此命令指定的查询或存储过程返回 timestamp 值,该值用于选择变更集并将其应用于每个对等方。在当前同步会话期间,该命令会提供一个新的 timestamp 值。将对上次同步会话期间的 timestamp 值之后和新的 timestamp 值之前所做的变更进行同步。然后,新值将存储起来并用作下一个会话的起始点。

示例

以下代码示例指定一条从对等方检索新 timestamp 值的命令。在此情况下,MIN_ACTIVE_ROWVERSION 从 SQL Server 数据库返回一个 timestamp 值。(MIN_ACTIVE_ROWVERSION 是在 SQL Server 2005 Service Pack 2 中引入的。)使用时间戳值的原因是对等数据库中的跟踪列包含时间戳值。若要在完整示例的上下文中查看此代码,请参见如何为协作同步设置服务器数据库(非 SQL Server)

SqlCommand selectNewTimestampCommand = new SqlCommand();
string newTimestampVariable = "@" + DbSyncSession.SyncNewTimestamp;
selectNewTimestampCommand.CommandText = "SELECT " + newTimestampVariable + " = min_active_rowversion() - 1";
selectNewTimestampCommand.Parameters.Add(newTimestampVariable, SqlDbType.Timestamp);
selectNewTimestampCommand.Parameters[newTimestampVariable].Direction = ParameterDirection.Output;

sampleProvider.SelectNewTimestampCommand = selectNewTimestampCommand;
Dim newTimestampVariable As String = "@" + DbSyncSession.SyncNewTimestamp

Dim selectNewTimestampCommand As New SqlCommand()

With selectNewTimestampCommand
    .CommandText = "SELECT " + newTimestampVariable + " = min_active_rowversion() - 1"
    .Parameters.Add(newTimestampVariable, SqlDbType.Timestamp)
    .Parameters(newTimestampVariable).Direction = ParameterDirection.Output
End With

sampleProvider.SelectNewTimestampCommand = selectNewTimestampCommand

请参阅

参考

DbSyncProvider类

DbSyncProvider 成员

Microsoft.Synchronization.Data 命名空间