방법: 끌어오기 구독 만들기(Replication Transact-SQL Programming)

끌어오기 구독은 복제 저장 프로시저를 사용하여 프로그래밍 방식으로 만들 수 있습니다. 사용되는 저장 프로시저는 구독이 속한 게시 유형에 따라 달라집니다.

스냅숏 또는 트랜잭션 게시에 끌어오기 구독을 만들려면

  1. 게시자에서 sp_helppublication(Transact-SQL)을 실행하여 게시에서 끌어오기 구독을 지원하는지 확인합니다.

    • 결과 집합의 allow_pull 값이 1이면 게시에서 끌어오기 구독을 지원합니다.

    • allow_pull 값이 0이면 sp_changepublication(Transact-SQL)을 실행하고 @propertyallow_pull을 지정하고 @value에 true를 지정합니다.

  2. 구독자에서 sp_addpullsubscription(Transact-SQL)을 실행합니다. @publisher@publication을 지정합니다. 구독 업데이트에 대한 자세한 내용은 방법: 트랜잭션 게시에 업데이트할 수 있는 구독 만들기(복제 Transact-SQL 프로그래밍)을 참조하십시오.

  3. 구독자에서 sp_addpullsubscription_agent(Transact-SQL)를 실행하고 다음을 지정합니다.

    • @publisher, @publisher_db@publication 매개 변수

    • @job_login@job_password에 대해 구독자에서 배포 에이전트가 실행되는 Microsoft Windows 자격 증명

      [!참고]

      Windows 통합 인증을 사용하여 만든 연결은 항상 @job_login@job_password로 지정한 Windows 자격 증명만 사용합니다. 배포 에이전트는 항상 Windows 통합 인증을 사용하여 구독자에 대한 로컬 연결을 만듭니다. 기본적으로 에이전트는 Windows 통합 인증을 사용하여 배포자에 연결합니다.

    • (옵션) 배포자에 연결할 때 SQL Server 인증을 사용해야 하는 경우 @distributor_security_mode0 값과 @distributor_login@distributor_password에 Microsoft SQL Server 로그인 정보 지정

    • 이 구독에 대한 배포 에이전트 작업 일정. 자세한 내용은 방법: 동기화 일정 지정(복제 Transact-SQL 프로그래밍)을 참조하십시오.

  4. 게시자에서 sp_addsubscription(Transact-SQL)을 실행하여 끌어오기 구독을 등록합니다. @publication, @subscriber@destination_db를 지정하여 @subscription_type의 값을 pull로 지정합니다.

병합 게시에 끌어오기 구독을 만들려면

  1. 게시자에서 sp_helpmergepublication(Transact-SQL)을 실행하여 게시에서 끌어오기 구독을 지원하는지 확인합니다.

    • 결과 집합의 allow_pull 값이 1이면 게시에서 끌어오기 구독을 지원합니다.

    • allow_pull 값이 0이면 sp_changemergepublication(Transact-SQL)을 실행하고 @propertyallow_pull을 지정하고 @value에 true를 지정합니다.

  2. 구독자에서 sp_addmergepullsubscription(Transact-SQL)을 실행합니다. @publisher, @publisher_db, @publication 및 다음 매개 변수를 지정합니다.

    • @subscriber_type - 클라이언트 구독에 local을 지정하고 서버 구독에 global을 지정합니다.

    • @subscription_priority - 구독의 우선 순위를 지정합니다(0.00 ~ 99.99). 이 지정은 서버 구독에만 필요합니다.

      자세한 내용은 고급 병합 복제 충돌 감지 및 해결을 참조하십시오.

  3. 구독자에서 sp_addmergepullsubscription_agent(Transact-SQL)를 실행하고 다음 매개 변수를 지정합니다.

    • @publisher, @publisher_db@publication

    • @job_login@job_password에 대해 구독자에서 병합 에이전트가 실행되는 Microsoft Windows 자격 증명

      [!참고]

      Windows 통합 인증을 사용하여 만든 연결은 항상 @job_login@job_password로 지정한 Windows 자격 증명만 사용합니다. 병합 에이전트는 항상 Windows 통합 인증을 사용하여 구독자에 대한 로컬 연결을 만듭니다. 기본적으로 에이전트는 Windows 통합 인증을 사용하여 배포자 및 게시자에 연결합니다.

    • (옵션) 배포자에 연결할 때 SQL Server 인증을 사용해야 하는 경우 @distributor_security_mode0 값과 @distributor_login@distributor_password에 SQL Server 로그인 정보 지정

    • (옵션) 게시자에 연결할 때 SQL Server 인증을 사용해야 하는 경우 @publisher_security_mode0 값과 @publisher_login@publisher_password에 SQL Server 로그인 정보 지정

    • 이 구독에 대한 병합 에이전트 작업 일정. 자세한 내용은 방법: 동기화 일정 지정(복제 Transact-SQL 프로그래밍)을 참조하십시오.

  4. 게시자에서 sp_addmergesubscription(Transact-SQL)을 실행합니다. @publication, @subscriber, @subscriber_db를 지정하고 @subscription_type의 값을 pull로 지정하면 끌어오기 구독이 등록됩니다.

다음은 트랜잭션 게시에 끌어오기 구독을 만드는 예입니다. 구독자에서 첫 번째 일괄 처리가 실행되고 두 번째 일괄 처리는 게시자에서 실행됩니다. 로그인 및 암호 값은 sqlcmd 스크립팅 변수를 사용하여 런타임에 제공됩니다.

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

-- Execute this batch at the Subscriber.
DECLARE @publication AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB AS sysname;
SET @publication = N'AdvWorksProductTran';
SET @publisher = $(PubServer);
SET @publicationDB = N'AdventureWorks2008R2';

-- At the subscription database, create a pull subscription 
-- to a transactional publication.
USE [AdventureWorks2008R2Replica]
EXEC sp_addpullsubscription 
  @publisher = @publisher, 
  @publication = @publication, 
  @publisher_db = @publicationDB;

-- Add an agent job to synchronize the pull subscription.
EXEC sp_addpullsubscription_agent 
  @publisher = @publisher, 
  @publisher_db = @publicationDB, 
  @publication = @publication, 
  @distributor = @publisher, 
  @job_login = $(Login), 
  @job_password = $(Password);
GO
-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

-- Execute this batch at the Publisher.
DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
SET @publication = N'AdvWorksProductTran';
SET @subscriber = $(SubServer);
SET @subscriptionDB = N'AdventureWorks2008R2Replica';

-- At the Publisher, register the subscription, using the defaults.
EXEC sp_addsubscription 
  @publication = @publication, 
  @subscriber = @subscriber, 
  @destination_db = @subscriptionDB, 
  @subscription_type = N'pull',
  @status = N'subscribed';
GO

다음은 병합 게시에 끌어오기 구독을 만드는 예입니다. 구독자에서 첫 번째 일괄 처리가 실행되고 두 번째 일괄 처리는 게시자에서 실행됩니다. 로그인 및 암호 값은 sqlcmd 스크립팅 변수를 사용하여 런타임에 제공됩니다.

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

-- Execute this batch at the Subscriber.
DECLARE @publication AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB AS sysname;
DECLARE @hostname AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
SET @publisher = $(PubServer);
SET @publicationDB = N'AdventureWorks2008R2';
SET @hostname = N'adventure-works\david8';

-- At the subscription database, create a pull subscription 
-- to a merge publication.
USE [AdventureWorks2008R2Replica]
EXEC sp_addmergepullsubscription 
  @publisher = @publisher, 
  @publication = @publication, 
  @publisher_db = @publicationDB;

-- Add an agent job to synchronize the pull subscription. 
EXEC sp_addmergepullsubscription_agent 
  @publisher = @publisher, 
  @publisher_db = @publicationDB, 
  @publication = @publication, 
  @distributor = @publisher, 
  @job_login = $(Login), 
  @job_password = $(Password),
  @hostname = @hostname;
GO
-- Execute this batch at the Publisher.
DECLARE @myMergePub  AS sysname;
DECLARE @mySub       AS sysname;
DECLARE @mySubDB     AS sysname;

SET @myMergePub = N'AdvWorksSalesOrdersMerge';
SET @mySub = N'MYSUBSERVER';
SET @mySubDB = N'AdventureWorks2008R2Replica';

-- At the Publisher, register the subscription, using the defaults.
USE [AdventureWorks2008R2]
EXEC sp_addmergesubscription @publication = @myMergePub, 
@subscriber = @mySub, @subscriber_db = @mySubDB, 
@subscription_type = N'pull';
GO