次の方法で共有


TransPullSubscription.SynchronizationAgent Property

サブスクリプションの同期に使用できるディストリビューション エージェントのインスタンスを表すオブジェクトを取得します。

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

構文

'宣言
Public ReadOnly Property SynchronizationAgent As TransSynchronizationAgent
public TransSynchronizationAgent SynchronizationAgent { get; }
public:
property TransSynchronizationAgent^ SynchronizationAgent {
    TransSynchronizationAgent^ get ();
}
/** @property */
public TransSynchronizationAgent get_SynchronizationAgent ()
public function get SynchronizationAgent () : TransSynchronizationAgent

プロパティ値

TransSynchronizationAgent オブジェクトです。

解説

サブスクリプションを同期するために、返された TransSynchronizationAgent オブジェクトで Synchronize メソッドを呼び出します。

サブスクリプションを同期するために SynchronizationAgent を取得する前に、CommitPropertyChanges を呼び出してサーバーにプロパティの変更を保存します。

プル サブスクリプションが CreateSyncAgentByDefault に対して既定値 false で作成された場合、サブスクリプションのディストリビューション エージェント ジョブは作成されません。サブスクリプションの同期に使用する前に、返された TransSynchronizationAgent オブジェクトのプロパティをさらに指定しておく必要があります。

SynchronizationAgent プロパティを取得できるのは、サブスクライバ側の固定サーバー ロール sysadmin のメンバ、またはサブスクリプション データベースの固定データベース ロール db_owner のメンバだけです。

SynchronizationAgent プロパティを取得すると、sp_helppullsubscription を実行したのと同じことになります。

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

使用例

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

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

TransPullSubscription subscription;

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

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

    // If the pull subscription exists, then start the synchronization.
    if (subscription.LoadProperties())
    {
        // Check that we have enough metadata to start the agent.
        if (subscription.PublisherSecurity != null)
        {
            // Synchronously start the Distribution Agent for the subscription.
            subscription.SynchronizationAgent.Synchronize();
        }
        else
        {
            throw new ApplicationException("There is insufficent metadata to " +
                "synchronize the subscription. Recreate the subscription with " +
                "the agent job or supply the required agent properties at run time.");
        }
    }
    else
    {
        // Do something here if the pull subscription does not exist.
        throw new ApplicationException(String.Format(
            "A subscription to '{0}' does not exist on {1}",
            publicationName, subscriberName));
    }
}
catch (Exception ex)
{
    // Implement appropriate error handling here.
    throw new ApplicationException("The subscription could not be " +
        "synchronized. Verify that the subscription has " +
        "been defined correctly.", ex);
}
finally
{
    conn.Disconnect();
}
' Define the server, publication, and database names.
Dim subscriberName As String = subscriberInstance
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksProductTran"
Dim subscriptionDbName As String = "AdventureWorksReplica"
Dim publicationDbName As String = "AdventureWorks"

' 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 the pull subscription.
    subscription = New TransPullSubscription()
    subscription.ConnectionContext = conn
    subscription.DatabaseName = subscriptionDbName
    subscription.PublisherName = publisherName
    subscription.PublicationDBName = publicationDbName
    subscription.PublicationName = publicationName

    ' If the pull subscription exists, then start the synchronization.
    If subscription.LoadProperties() Then
        ' Check that we have enough metadata to start the agent.
        If Not subscription.PublisherSecurity Is Nothing Then

            ' Write agent output to a log file.
            subscription.SynchronizationAgent.Output = "distagent.log"
            subscription.SynchronizationAgent.OutputVerboseLevel = 2

            ' Synchronously start the Distribution Agent for the subscription.
            subscription.SynchronizationAgent.Synchronize()
        Else
            Throw New ApplicationException("There is insufficent metadata to " + _
             "synchronize the subscription. Recreate the subscription with " + _
             "the agent job or supply the required agent properties at run time.")
        End If
    Else
        ' Do something here if the pull subscription does not exist.
        Throw New ApplicationException(String.Format( _
         "A subscription to '{0}' does not exist on {1}", _
         publicationName, subscriberName))
    End If
Catch ex As Exception
    ' Implement appropriate error handling here.
    Throw New ApplicationException("The subscription could not be " + _
     "synchronized. Verify that the subscription has " + _
     "been defined correctly.", 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

変更履歴

リリース

履歴

2006 年 4 月 14 日

変更内容 :
  • TransSynchronizationAgent オブジェクトを使用するアプリケーションには、シングル スレッド アパートメントのスレッド モデルの使用に関する制限はありません。「解説」セクションの、この制限に関する記述を削除しました。