밀어넣기 구독 동기화Synchronize a Push Subscription

이 항목에서는 SQL Server 2017SQL Server 2017 , SQL Server Management StudioSQL Server Management Studio복제 에이전트 또는 RMO(복제 관리 개체)를 사용하여에서 밀어넣기 구독을 동기화하는 방법에 대해 설명합니다.This topic describes how to synchronize a push subscription in SQL Server 2017SQL Server 2017 by using SQL Server Management StudioSQL Server Management Studio, replication agents, or Replication Management Objects (RMO).

항목 내용In This Topic

SQL Server Management Studio 사용 Using SQL Server Management Studio

구독은 배포 에이전트(스냅숏 및 트랜잭션 복제의 경우) 또는 병합 에이전트(병합 복제의 경우)에 의해 동기화됩니다.Subscriptions are synchronized by the Distribution Agent (for snapshot and transactional replication) or the Merge Agent (for merge replication). 에이전트는 지속적으로 실행하거나 수요에 따라 실행하거나 일정에 따라 실행할 수 있습니다.Agents can run continuously, run on demand, or run on a schedule. 동기화 일정을 설정하는 방법은 동기화 일정 지정을 참조하세요.For more information about specifying synchronization schedules, see Specify Synchronization Schedules.

MicrosoftMicrosoft SQL Server Management StudioSQL Server Management Studio로컬 게시로컬 구독 폴더와 복제 모니터의 모든 구독 탭에서 요청 시 구독을 동기화합니다.Synchronize a subscription on demand from the Local Publications and Local Subscriptions folders in MicrosoftMicrosoft SQL Server Management StudioSQL Server Management Studio and the All Subscriptions tab in Replication Monitor. Oracle 게시에 대한 구독은 구독자에서 요청 시 동기화할 수 없습니다.Subscriptions to Oracle publications cannot be synchronized on demand from the Subscriber. 복제 모니터를 시작하는 방법은 복제 모니터 시작을 참조하세요.For information about starting Replication Monitor, see Start the Replication Monitor.

Management Studio에서 요청 시 밀어넣기 구독을 동기화하려면(게시자)To synchronize a push subscription on demand in Management Studio (at the Publisher)

  1. Management StudioManagement Studio에서 게시자에 연결한 다음 해당 서버 노드를 확장합니다.Connect to the Publisher in Management StudioManagement Studio, and then expand the server node.

  2. 복제 폴더를 확장한 다음 로컬 게시 폴더를 확장합니다.Expand the Replication folder, and then expand the Local Publications folder.

  3. 구독을 동기화할 게시를 확장합니다.Expand the publication for which you want to synchronize subscriptions.

  4. 동기화할 구독을 마우스 오른쪽 단추로 클릭한 다음 동기화 상태 보기를 클릭합니다.Right-click the subscription you want to synchronize, and then click View Synchronization Status.

  5. 동기화 상태 보기 - <Subscriber>:<SubscriptionDatabase> 대화 상자에서 시작을 클릭합니다.In the View Synchronization Status - <Subscriber>:<SubscriptionDatabase> dialog box, click Start. 동기화가 완료되면 동기화 완료 라는 메시지가 표시됩니다.When synchronization is complete, the message Synchronization completed is displayed.

  6. 닫기를 클릭합니다.Click Close.

Management Studio에서 요청 시 밀어넣기 구독을 동기화하려면(구독자)To synchronize a push subscription on demand in Management Studio (at the Subscriber)

  1. Management StudioManagement Studio에서 구독자에 연결한 다음 해당 서버 노드를 확장합니다.Connect to the Subscriber in Management StudioManagement Studio, and then expand the server node.

  2. 복제 폴더를 확장한 다음 로컬 구독 폴더를 확장합니다.Expand the Replication folder, and then expand the Local Subscriptions folder.

  3. 동기화할 구독을 마우스 오른쪽 단추로 클릭한 다음 동기화 상태 보기를 클릭합니다.Right-click the subscription you want to synchronize, and then click View Synchronization Status.

  4. 배포자 연결 설정에 대한 메시지가 표시됩니다.A message is displayed about establishing a connection to the Distributor. 확인을 클릭합니다.Click OK.

  5. 동기화 상태 보기 - <Subscriber>:<SubscriptionDatabase> 대화 상자에서 시작을 클릭합니다.In the View Synchronization Status - <Subscriber>:<SubscriptionDatabase> dialog box, click Start. 동기화가 완료되면 동기화 완료 라는 메시지가 표시됩니다.When synchronization is complete, the message Synchronization completed is displayed.

  6. 닫기를 클릭합니다.Click Close.

복제 모니터에서 요청 시 밀어넣기 구독을 동기화하려면To synchronize a push subscription on demand in Replication Monitor

  1. 복제 모니터에서 왼쪽 창의 게시자 그룹을 확장하고 해당 게시자를 확장한 다음 해당 게시를 클릭합니다.In Replication Monitor, expand a Publisher group in the left pane, expand a Publisher, and then click a publication.

  2. 모든 구독 탭을 클릭합니다.Click the All Subscriptions tab.

  3. 동기화할 구독을 마우스 오른쪽 단추로 클릭한 다음 동기화 시작을 클릭합니다.Right-click the subscription you want to synchronize, and then click Start Synchronizing.

  4. 동기화 진행률을 보려면 해당 구독을 마우스 오른쪽 단추로 클릭한 다음 자세히 보기를 클릭합니다.To view synchronization progress, right-click the subscription, and then click View Details.

복제 에이전트 사용 Using Replication Agents

밀어넣기 구독은 명령 프롬프트에서 적합한 복제 에이전트 실행 파일을 호출하여 프로그래밍 방식으로 요청 시 동기화할 수 있습니다.Push subscriptions can be synchronized programmatically and on-demand by invoking the appropriate replication agent executable file from the command prompt. 호출한 복제 에이전트 실행 파일은 밀어넣기 구독이 속한 게시 유형에 따라 달라집니다.The replication agent executable file that is invoked will depend on the type of publication to which the push subscription belongs.

배포 에이전트를 시작하여 트랜잭션 게시에 밀어넣기 구독을 동기화하려면To start the Distribution Agent to synchronize a push subscription to a transactional publication

  1. 배포자의 명령 프롬프트나 배치 파일에서 distrib.exe를 실행하고From the command prompt or in a batch file at the Distributor, execute distrib.exe. 다음 명령줄 인수를 지정합니다.Specify the following command-line arguments:

    • -Publisher-Publisher

    • -PublisherDB-PublisherDB

    • -Distributor-Distributor

    • -Subscriber-Subscriber

    • -SubscriberDB-SubscriberDB

    • -SubscriptionType = 0-SubscriptionType = 0

      SQL Server 인증을 사용하는 경우 다음 인수도 지정해야 합니다.If you are using SQL Server Authentication, you must also specify the following arguments:

    • -DistributorLogin-DistributorLogin

    • -DistributorPassword-DistributorPassword

    • -DistributorSecurityMode = 0-DistributorSecurityMode = 0

    • -PublisherLogin-PublisherLogin

    • -PublisherPassword-PublisherPassword

    • -PublisherSecurityMode = 0-PublisherSecurityMode = 0

    • -SubscriberLogin-SubscriberLogin

    • -SubscriberPassword-SubscriberPassword

    • -SubscriberSecurityMode = 0-SubscriberSecurityMode = 0

      중요

      가능하면 Windows 인증을 사용하세요.When possible, use Windows Authentication.

병합 에이전트를 시작하여 병합 게시에 밀어넣기 구독을 동기화하려면To start the Merge Agent to synchronize a push subscription to a merge publication

  1. 배포자의 명령 프롬프트나 배치 파일에서 replmerg.exe를 실행하고From the command prompt or in a batch file at the Distributor, execute replmerg.exe. 다음 명령줄 인수를 지정합니다.Specify the following command-line arguments:

    • -Publisher-Publisher

    • -PublisherDB-PublisherDB

    • -Publication-Publication

    • -Distributor-Distributor

    • -Subscriber-Subscriber

    • -SubscriberDB-SubscriberDB

    • -SubscriptionType = 0-SubscriptionType = 0

      SQL Server 인증을 사용하는 경우 다음 인수도 지정해야 합니다.If you are using SQL Server Authentication, you must also specify the following arguments:

    • -DistributorLogin-DistributorLogin

    • -DistributorPassword-DistributorPassword

    • -DistributorSecurityMode = 0-DistributorSecurityMode = 0

    • -PublisherLogin-PublisherLogin

    • -PublisherPassword-PublisherPassword

    • -PublisherSecurityMode = 0-PublisherSecurityMode = 0

    • -SubscriberLogin-SubscriberLogin

    • -SubscriberPassword-SubscriberPassword

    • -SubscriberSecurityMode = 0-SubscriberSecurityMode = 0

      중요

      가능하면 Windows 인증을 사용하세요.When possible, use Windows Authentication.

예(복제 에이전트) Examples (Replication Agents)

다음 예에서는 배포 에이전트를 시작하여 밀어넣기 구독을 동기화합니다.The following example starts the Distribution Agent to synchronize a push subscription.


REM -- Declare the variables.  
SET Publisher=%instancename%  
SET Subscriber=%instancename%  
SET PublicationDB=AdventureWorks2012  
SET SubscriptionDB=AdventureWorks2012Replica   
SET Publication=AdvWorksProductsTran  

REM -- Start the Distribution Agent with four subscription streams.  
REM -- The following command must be supplied without line breaks.  
"C:\Program Files\Microsoft SQL Server\120\COM\DISTRIB.EXE" -Subscriber %Subscriber%   
-SubscriberDB %SubscriptionDB% -SubscriberSecurityMode 1 -Publication %Publication%   
-Publisher %Publisher% -PublisherDB %PublicationDB% -Distributor %Publisher%   
-DistributorSecurityMode 1 -Continuous -SubscriptionType 0 -SubscriptionStreams 4  

다음 예에서는 병합 에이전트를 시작하여 밀어넣기 구독을 동기화합니다.The following example starts the Merge Agent to synchronize a push subscription.


REM -- Declare the variables.  
SET Publisher=%instancename%  
SET Subscriber=%instancename%  
SET PublicationDB=AdventureWorks2012  
SET SubscriptionDB=AdventureWorks2012Replica   
SET Publication=AdvWorksSalesOrdersMerge  

REM -- Start the Merge Agent.  
REM -- The following command must be supplied without line breaks.  
"C:\Program Files\Microsoft SQL Server\120\COM\REPLMERG.EXE"  -Publisher %Publisher%   
-Subscriber  %Subscriber%  -Distributor %Publisher% -PublisherDB  %PublicationDB%   
-SubscriberDB %SubscriptionDB% -Publication %Publication% -PublisherSecurityMode 1   
-OutputVerboseLevel 3  -Output -SubscriberSecurityMode 1  -SubscriptionType 0   
-DistributorSecurityMode 1  

RMO(복제 관리 개체) 사용 Using Replication Management Objects (RMO)

RMO(복제 관리 개체) 및 관리 코드 액세스를 사용하여 복제 에이전트 기능에 프로그래밍 방식으로 밀어넣기 구독을 동기화할 수 있습니다.You can synchronize push subscriptions programmatically by using Replication Management Objects (RMO) and managed code access to replication agent functionalities. 밀어넣기 구독을 동기화하는 데 사용하는 클래스는 구독이 속한 게시 유형에 따라 달라집니다.The classes that you use to synchronize a push subscription depend on the type of publication to which the subscription belongs.

참고

동기화가 응용 프로그램에 영향을 미치지 않고 자율적으로 실행하도록 하려면 에이전트를 비동기적으로 시작합니다.If you want to start a synchronization that runs autonomously without affecting your application, start the agent asynchronously. 그러나 진행률 표시줄을 표시하기 위해 동기화 프로세스 동안 동기화 결과를 모니터링하고 에이전트에서 콜백을 받으려면 에이전트를 동기적으로 시작해야 합니다.However, if you want to monitor the outcome of the synchronization and receive callbacks from the agent during the synchronization process (for example, if you want to display a progress bar), you should start the agent synchronously. For MicrosoftMicrosoft SQL Server 2005 Express EditionSQL Server 2005 Express Edition Subscribers, you must start the agent synchronously.For MicrosoftMicrosoft SQL Server 2005 Express EditionSQL Server 2005 Express Edition Subscribers, you must start the agent synchronously.

스냅숏 또는 트랜잭션 게시에 밀어넣기 구독을 동기화하려면To synchronize a push subscription to a snapshot or transactional publication

  1. ServerConnection 클래스를 사용하여 배포자 연결을 만듭니다.Create a connection to the Distributor by using the ServerConnection class.

  2. TransSubscription 클래스의 인스턴스를 만들고 다음 속성을 설정합니다.Create an instance of the TransSubscription class and set the following properties:

  3. LoadProperties 메서드를 호출하여 나머지 구독 속성을 얻습니다.Call the LoadProperties method to get the remaining subscription properties. 이 메서드가 false를 반환하는 경우 구독이 있는지 확인합니다.If this method returns false, verify that the subscription exists.

  4. 다음 방법 중 하나로 배포자에서 배포 에이전트를 시작합니다.Start the Distribution Agent at the Distributor in one of the following ways:

    • 2단계에서 만든 TransSubscription의 인스턴스에서 SynchronizeWithJob 메서드를 호출합니다.Call the SynchronizeWithJob method on the instance of TransSubscription from step 2. 이 메서드는 배포 에이전트를 비동기적으로 시작하고 에이전트 작업이 실행되는 동안 응용 프로그램에 대한 반환을 즉시 제어합니다.This method starts the Distribution Agent asynchronously, and control immediately returns to your application while the agent job is running. CreateSyncAgentByDefaultfalse 값을 사용하여 구독을 만든 경우 이 메서드를 호출할 수 없습니다.You cannot call this method if the subscription was created with a value of false for CreateSyncAgentByDefault.

    • SynchronizationAgent 속성에서 TransSynchronizationAgent 클래스의 인스턴스를 가져오고 Synchronize 메서드를 호출합니다.Obtain an instance of the TransSynchronizationAgent class from the SynchronizationAgent property, and call the Synchronize method. 이 메서드는 에이전트를 동기적으로 시작하고 실행 중인 에이전트 작업에 대한 제어는 그대로 유지됩니다.This method starts the agent synchronously, and control remains with the running agent job. 동기화 실행 중에는 에이전트를 실행하면서 Status 이벤트를 처리할 수 있습니다.During synchronous execution you can handle the Status event while the agent is running.

병합 게시에 밀어넣기 구독을 동기화하려면To synchronize a push subscription to a merge publication

  1. ServerConnection 클래스를 사용하여 배포자 연결을 만듭니다.Create a connection to the Distributor by using the ServerConnection class.

  2. MergeSubscription 클래스의 인스턴스를 만들고 다음 속성을 설정합니다.Create an instance of the MergeSubscription class, and set the following properties:

  3. LoadProperties 메서드를 호출하여 나머지 구독 속성을 얻습니다.Call the LoadProperties method to get the remaining subscription properties. 이 메서드가 false를 반환하는 경우 구독이 있는지 확인합니다.If this method returns false, verify that the subscription exists.

  4. 다음 방법 중 하나로 배포자에서 병합 에이전트를 시작합니다.Start the Merge Agent at the Distributor in one of the following ways:

    • 2단계에서 만든 MergeSubscription의 인스턴스에서 SynchronizeWithJob 메서드를 호출합니다.Call the SynchronizeWithJob method on the instance of MergeSubscription from step 2. 이 메서드는 병합 에이전트를 비동기적으로 시작하고 에이전트 작업이 실행되는 동안 응용 프로그램에 대한 반환을 즉시 제어합니다.This method starts the Merge Agent asynchronously, and control immediately returns to your application while the agent job is running. CreateSyncAgentByDefaultfalse 값을 사용하여 구독을 만든 경우 이 메서드를 호출할 수 없습니다.You cannot call this method if the subscription was created with a value of false for CreateSyncAgentByDefault.

    • SynchronizationAgent 속성에서 MergeSynchronizationAgent 클래스의 인스턴스를 가져오고 Synchronize 메서드를 호출합니다.Obtain an instance of the MergeSynchronizationAgent class from the SynchronizationAgent property, and call the Synchronize method. 이 메서드는 병합 에이전트를 동기적으로 시작하고 실행 중인 에이전트 작업에 대한 제어는 그대로 유지됩니다.This method starts the Merge Agent synchronously, and control remains with the running agent job. 동기화 실행 중에는 에이전트를 실행하면서 Status 이벤트를 처리할 수 있습니다.During synchronous execution, you can handle the Status event while the agent is running.

예(RMO) Examples (RMO)

다음은 트랜잭션 게시에 밀어넣기 구독을 동기화하는 예로, 에이전트 작업을 사용하여 에이전트를 비동기적으로 시작합니다.This example synchronizes a push subscription to a transactional publication, where the agent is started asynchronously using the agent job.

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

/// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);

TransSubscription subscription;

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

	// Instantiate the push subscription.
	subscription = new TransSubscription();
	subscription.ConnectionContext = conn;
	subscription.DatabaseName = publicationDbName;
	subscription.PublicationName = publicationName;
	subscription.SubscriptionDBName = subscriptionDbName;
	subscription.SubscriberName = subscriberName;

	// If the push subscription and the job exists, start the agent job.
	if (subscription.LoadProperties() && subscription.AgentJobId != null)
	{
		// Start the Distribution Agent asynchronously.
		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)
{
	// Implement appropriate error handling here.
	throw new ApplicationException("The subscription could not be synchronized.", 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 = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"

' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

Dim subscription As TransSubscription

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

    ' Instantiate the push subscription.
    subscription = New TransSubscription()
    subscription.ConnectionContext = conn
    subscription.DatabaseName = publicationDbName
    subscription.PublicationName = publicationName
    subscription.SubscriptionDBName = subscriptionDbName
    subscription.SubscriberName = subscriberName

    ' If the push subscription and the job exists, start the agent job.
    If subscription.LoadProperties() And Not subscription.AgentJobId Is Nothing Then
        ' Start the Distribution Agent asynchronously.
        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
    ' Implement appropriate error handling here.
    Throw New ApplicationException("The subscription could not be synchronized.", ex)
Finally
    conn.Disconnect()
End Try

다음은 트랜잭션 게시에 밀어넣기 구독을 동기화하는 예로, 에이전트를 동기적으로 시작합니다.This example synchronizes a push subscription to a transactional publication, where the agent is started synchronously.

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

// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);

TransSubscription subscription;

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

	// Define the push subscription.
	subscription = new TransSubscription();
	subscription.ConnectionContext = conn;
	subscription.DatabaseName = publicationDbName;
	subscription.PublicationName = publicationName;
	subscription.SubscriptionDBName = subscriptionDbName;
	subscription.SubscriberName = subscriberName;

	// If the push subscription exists, start the synchronization.
	if (subscription.LoadProperties())
	{
		// Check that we have enough metadata to start the agent.
		if (subscription.SubscriberSecurity != 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 push subscription does not exist.
		throw new ApplicationException(String.Format(
			"The 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.", 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 = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"

' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

Dim subscription As TransSubscription

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

    ' Define the push subscription.
    subscription = New TransSubscription()
    subscription.ConnectionContext = conn
    subscription.DatabaseName = publicationDbName
    subscription.PublicationName = publicationName
    subscription.SubscriptionDBName = subscriptionDbName
    subscription.SubscriberName = subscriberName

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

            ' 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 push subscription does not exist.
        Throw New ApplicationException(String.Format( _
         "The 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.", ex)
Finally
    conn.Disconnect()
End Try

다음은 병합 게시에 밀어넣기 구독을 동기화하는 예로, 에이전트 작업을 사용하여 에이전트를 비동기적으로 시작합니다.This example synchronizes a push subscription to a merge publication, where the agent is started asynchronously using the agent job.

// Define the server, publication, and database names.
string subscriberName = subscriberInstance;
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";

// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);

MergeSubscription subscription;

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

	// Define push subscription.
	subscription = new MergeSubscription();
	subscription.ConnectionContext = conn;
	subscription.DatabaseName = publicationDbName;
	subscription.PublicationName = publicationName;
	subscription.SubscriptionDBName = subscriptionDbName;
	subscription.SubscriberName = subscriberName;

	// If the push subscription and the job exists, start the agent job.
	if (subscription.LoadProperties() && subscription.AgentJobId != null)
	{
		// Start the Merge Agent asynchronously.
		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)
{
	// Implement appropriate error handling here.
	throw new ApplicationException("The subscription could not be synchronized.", 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 = "AdvWorksSalesOrdersMerge"
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"

' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

Dim subscription As MergeSubscription

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

    ' Define push subscription.
    subscription = New MergeSubscription()
    subscription.ConnectionContext = conn
    subscription.DatabaseName = publicationDbName
    subscription.PublicationName = publicationName
    subscription.SubscriptionDBName = subscriptionDbName
    subscription.SubscriberName = subscriberName

    ' If the push subscription and the job exists, start the agent job.
    If subscription.LoadProperties() And Not subscription.AgentJobId Is Nothing Then
        ' Start the Merge Agent asynchronously.
        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
    ' Implement appropriate error handling here.
    Throw New ApplicationException("The subscription could not be synchronized.", ex)
Finally
    conn.Disconnect()
End Try

다음은 병합 게시에 밀어넣기 구독을 동기화하는 예로, 에이전트를 동기적으로 시작합니다.This example synchronizes a push subscription to a merge publication, where the agent is started synchronously.

// Define the server, publication, and database names.
string subscriberName = subscriberInstance;
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string subscriptionDbName = "AdventureWorks2012Replica";
string publicationDbName = "AdventureWorks2012";

// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);

MergeSubscription subscription;

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

	// Define the subscription.
	subscription = new MergeSubscription();
	subscription.ConnectionContext = conn;
	subscription.DatabaseName = publicationDbName;
	subscription.PublicationName = publicationName;
	subscription.SubscriptionDBName = subscriptionDbName;
	subscription.SubscriberName = subscriberName;

	// If the push subscription exists, start the synchronization.
	if (subscription.LoadProperties())
	{
		// Check that we have enough metadata to start the agent.
		if (subscription.SubscriberSecurity != null)
		{
			// Synchronously start the Merge 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 push subscription does not exist.
		throw new ApplicationException(String.Format(
			"The 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.", 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 = "AdvWorksSalesOrdersMerge"
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"

' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)

Dim subscription As MergeSubscription

Try
    ' Connect to the Publisher
    conn.Connect()

    ' Define the subscription.
    subscription = New MergeSubscription()
    subscription.ConnectionContext = conn
    subscription.DatabaseName = publicationDbName
    subscription.PublicationName = publicationName
    subscription.SubscriptionDBName = subscriptionDbName
    subscription.SubscriberName = subscriberName

    ' If the push subscription exists, start the synchronization.
    If subscription.LoadProperties() Then
        ' Check that we have enough metadata to start the agent.
        If Not subscription.SubscriberSecurity Is Nothing Then
            ' Synchronously start the Merge Agent for the subscription.
            ' Log agent messages to an output file.
            subscription.SynchronizationAgent.Output = "mergeagent.log"
            subscription.SynchronizationAgent.OutputVerboseLevel = 2
            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 push subscription does not exist.
        Throw New ApplicationException(String.Format( _
         "The 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.", ex)
Finally
    conn.Disconnect()
End Try

관련 항목:See Also

복제 관리 개체 개념 Replication Management Objects Concepts
데이터 동기화 Synchronize Data
Replication Security Best Practices Replication Security Best Practices