次の方法で共有


TransPullSubscription.SynchronizeWithJob Method

エージェント ジョブを開始してサブスクリプションの同期をとります。

名前空間: Microsoft.SqlServer.Replication
アセンブリ: Microsoft.SqlServer.Rmo (microsoft.sqlserver.rmo.dll 内)

構文

'宣言
Public Overrides Sub SynchronizeWithJob
public override void SynchronizeWithJob ()
public:
virtual void SynchronizeWithJob () override
public void SynchronizeWithJob ()
public override function SynchronizeWithJob ()

解説

ディストリビューション エージェントを同期的に開始するには、SynchronizationAgent プロパティによって返される TransSynchronizationAgent オブジェクトを使用します。

プル サブスクリプションが CreateSyncAgentByDefault に対して既定値 false で作成された場合、サブスクリプションのディストリビューション エージェント ジョブは作成されず、SynchronizeWithJob を呼び出すと例外が発生します。

現在ジョブが実行されている場合、StopSynchronizationJob メソッドを呼び出してジョブを停止します。

Microsoft SQL Server エージェント サービスが実行されていない場合、ジョブは開始することができません。また、スナップショットが生成されない場合、エージェント ジョブを実行してもサブスクリプションを同期しない可能性があります。

TransPullSubscription のこのインスタンスで追加のプロパティを設定する場合、SynchronizeWithJob を呼び出す前に CommitPropertyChanges を呼び出します。

SynchronizeWithJob メソッドを呼び出すことができるのは、サブスクライバ側の固定サーバー ロール sysadmin のメンバ、またはサブスクリプション データベースの固定データベース ロール db_owner のメンバだけです。

この名前空間、クラス、またはメンバは、.NET Framework 2.0 でのみサポートされています。

使用例

// Define server, publication, and database names.
String subscriberName = subscriberInstance;
String publisherName = publisherInstance;
String publicationName = "AdvWorksProductTran";
String publicationDbName = "AdventureWorks";
String subscriptionDbName = "AdventureWorksReplica";

// Create a connection to the Subscriber.
ServerConnection conn = new ServerConnection(subscriberName);

TransPullSubscription subscription;

try
{
    // Connect to the Subscriber.
    conn.Connect();

    // Define subscription properties.
    subscription = new TransPullSubscription();
    subscription.ConnectionContext = conn;
    subscription.DatabaseName = subscriptionDbName;
    subscription.PublisherName = publisherName;
    subscription.PublicationDBName = publicationDbName;
    subscription.PublicationName = publicationName;

    // If the pull subscription and the job exists, start the agent job.
    if (subscription.LoadProperties() && subscription.AgentJobId != null)
    {
        subscription.SynchronizeWithJob();
    }
    else
    {
        // Do something here if the subscription does not exist.
        throw new ApplicationException(String.Format(
            "A subscription to '{0}' does not exists on {1}",
            publicationName, subscriberName));
    }
}
catch (Exception ex)
{
    // Do appropriate error handling here.
    throw new ApplicationException("The subscription could not be synchronized.", ex);
}
finally
{
    conn.Disconnect();
}
' Define server, publication, and database names.
Dim subscriberName As String = subscriberInstance
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks"
Dim subscriptionDbName As String = "AdventureWorksReplica"

' Create a connection to the Subscriber.
Dim conn As ServerConnection = New ServerConnection(subscriberName)

Dim subscription As TransPullSubscription

Try
    ' Connect to the Subscriber.
    conn.Connect()

    ' Define subscription properties.
    subscription = New TransPullSubscription()
    subscription.ConnectionContext = conn
    subscription.DatabaseName = subscriptionDbName
    subscription.PublisherName = publisherName
    subscription.PublicationDBName = publicationDbName
    subscription.PublicationName = publicationName

    ' If the pull subscription and the job exists, start the agent job.
    If subscription.LoadProperties() And Not subscription.AgentJobId Is Nothing Then
        subscription.SynchronizeWithJob()
    Else
        ' Do something here if the subscription does not exist.
        Throw New ApplicationException(String.Format( _
         "A subscription to '{0}' does not exists on {1}", _
         publicationName, subscriberName))
    End If
Catch ex As Exception
    ' Do appropriate error handling here.
    Throw New ApplicationException("The subscription could not be synchronized.", ex)
Finally
    conn.Disconnect()
End Try

スレッド セーフ

この型の public static (Microsoft Visual Basic では共有 ) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

プラットフォーム

開発プラットフォーム

サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。

対象プラットフォーム

サポートされているプラットフォームの一覧については、「SQL Server 2005 のインストールに必要なハードウェアおよびソフトウェア」を参照してください。

参照

関連項目

TransPullSubscription Class
TransPullSubscription Members
Microsoft.SqlServer.Replication Namespace

その他の技術情報

プル サブスクリプションを同期する方法 (RMO プログラミング)