밀어넣기 구독 삭제

이 항목에서는 SQL Server Management Studio, Transact-SQL 또는 RMO(복제 관리 개체)를 사용하여 SQL Server 2012에서 밀어넣기 구독을 삭제하는 방법에 대해 설명합니다.

항목 내용

  • 밀어넣기 구독을 삭제하려면:

    SQL Server Management Studio

    Transact-SQL

    RMO(복제 관리 개체)

SQL Server Management Studio 사용

게시자(SQL Server Management Studio의 로컬 게시 폴더 사용) 또는 구독자(로컬 구독 폴더 사용)에서 밀어넣기 구독을 삭제합니다. 구독을 삭제해도 구독에서 개체나 데이터가 제거되지는 않으며 개체나 데이터는 수동으로 제거해야 합니다.

게시자에서 밀어넣기 구독을 삭제하려면

  1. SQL Server Management Studio에서 게시자에 연결한 다음 해당 서버 노드를 확장합니다.

  2. 복제 폴더를 확장한 다음 로컬 게시 폴더를 확장합니다.

  3. 삭제할 구독과 연결된 게시를 확장합니다.

  4. 구독을 마우스 오른쪽 단추로 클릭한 다음 삭제를 클릭합니다.

  5. 확인 대화 상자에서 구독 정보를 삭제할 구독자에 연결할지 여부를 선택합니다. 구독자에 연결 확인란의 선택을 취소한 경우 나중에 구독자에 연결하여 해당 정보를 삭제해야 합니다.

구독자에서 밀어넣기 구독을 삭제하려면

  1. SQL Server Management Studio에서 구독자에 연결한 다음 해당 서버 노드를 확장합니다.

  2. 복제 폴더를 확장한 다음 로컬 구독 폴더를 확장합니다.

  3. 삭제할 구독을 마우스 오른쪽 단추로 클릭한 다음 삭제를 클릭합니다.

  4. 확인 대화 상자에서 구독 정보를 삭제할 게시자에 연결할지 여부를 선택합니다. 게시자에 연결 확인란의 선택을 취소한 경우 나중에 게시자에 연결하여 해당 정보를 삭제해야 합니다.

맨 위로 이동 링크와 함께 사용되는 화살표 아이콘[Top]

Transact-SQL 사용

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

스냅숏 또는 트랜잭션 게시에 대한 밀어넣기 구독을 삭제하려면

  1. 게시 데이터베이스의 게시자에서 sp_dropsubscription(Transact-SQL)을 실행합니다. @publication@subscriber를 지정합니다. @articleall 값을 지정합니다. (옵션) 배포자에 액세스할 수 없으면 @ignore_distributor에 대해 값 1을 지정하여 배포자에서 관련 개체를 제거하지 않고 구독을 삭제합니다.

  2. 구독 데이터베이스의 구독자에서 sp_subscription_cleanup(Transact-SQL)을 실행하여 구독 데이터베이스의 복제 메타데이터를 제거합니다.

병합 게시에 대한 밀어내기 구독을 삭제하려면

  1. 게시자에서 @publication, @subscriber@subscriber_db를 지정하고 sp_dropmergesubscription(Transact-SQL)을 실행합니다. (옵션) 배포자에 액세스할 수 없으면 @ignore_distributor에 대해 값 1을 지정하여 배포자에서 관련 개체를 제거하지 않고 구독을 삭제합니다.

  2. 구독 데이터베이스의 구독자에서 sp_mergesubscription_cleanup(Transact-SQL)을 실행합니다. @publisher, @publisher_db@publication을 지정합니다. 이렇게 하면 구독 데이터베이스에서 병합 메타데이터가 제거됩니다.

예(Transact-SQL)

이 예에서는 트랜잭션 게시에 대한 밀어넣기 구독을 삭제합니다.

-- 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".

-- This batch is executed at the Publisher to remove 
-- a pull or push subscription to a transactional publication.
DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
SET @publication = N'AdvWorksProductTran';
SET @subscriber = $(SubServer);

USE [AdventureWorks2012]
EXEC sp_dropsubscription 
  @publication = @publication, 
  @article = N'all',
  @subscriber = @subscriber;
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".

-- This batch is executed at the Publisher to remove 
-- a pull or push subscription to a merge publication.
DECLARE @publication AS sysname;
DECLARE @subscriber AS sysname;
DECLARE @subscriptionDB AS sysname;
SET @publication = N'AdvWorksSalesOrdersMerge';
SET @subscriber = $(SubServer);
SET @subscriptionDB = N'AdventureWorks2012Replica';

USE [AdventureWorks2012]
EXEC sp_dropmergesubscription 
  @publication = @publication, 
  @subscriber = @subscriber, 
  @subscriber_db = @subscriptionDB;
GO

맨 위로 이동 링크와 함께 사용되는 화살표 아이콘[Top]

RMO(복제 관리 개체) 사용

밀어넣기 구독을 삭제하는 데 사용되는 RMO 클래스는 밀어넣기 구독이 구독하는 게시의 유형에 따라 달라집니다.

스냅숏 또는 트랜잭션 게시에 대한 밀어넣기 구독을 삭제하려면

  1. ServerConnection 클래스를 사용하여 구독자 연결을 만듭니다.

  2. TransSubscription 클래스의 인스턴스를 만듭니다.

  3. PublicationName, SubscriptionDBName, SubscriberNameDatabaseName 속성을 설정합니다.

  4. ConnectionContext 속성을 1단계의 ServerConnection으로 설정합니다.

  5. IsExistingObject 속성을 확인하여 구독이 존재하는지 확인합니다. 이 속성의 값이 false이면 2단계에서 구독 속성이 올바르게 정의되지 않았거나 구독이 없는 것입니다.

  6. Remove 메서드를 호출합니다.

병합 게시에 대한 밀어내기 구독을 삭제하려면

  1. ServerConnection 클래스를 사용하여 구독자 연결을 만듭니다.

  2. MergeSubscription 클래스의 인스턴스를 만듭니다.

  3. PublicationName, SubscriptionDBName, SubscriberNameDatabaseName 속성을 설정합니다.

  4. ConnectionContext 속성을 1단계의 ServerConnection으로 설정합니다.

  5. IsExistingObject 속성을 확인하여 구독이 존재하는지 확인합니다. 이 속성의 값이 false이면 2단계에서 구독 속성이 올바르게 정의되지 않았거나 구독이 없는 것입니다.

  6. Remove 메서드를 호출합니다.

예(RMO)

RMO(복제 관리 개체)를 사용하여 프로그래밍 방식으로 밀어넣기 구독을 삭제할 수 있습니다.

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

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

            // Create the objects that we need.
            TransSubscription subscription;

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

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

                // Delete the pull subscription, if it exists.
                if (subscription.IsExistingObject)
                {
                    // Delete the pull subscription at the Subscriber.
                    subscription.Remove();
                }
                else
                {
                    throw new ApplicationException(String.Format(
                        "The subscription to {0} does not exist on {1}",
                        publicationName, subscriberName));
                }
            }
            catch (Exception ex)
            {
                // Implement the appropriate error handling here.
                throw new ApplicationException(String.Format(
                    "The subscription to {0} could not be deleted.", publicationName), ex);
            }
            finally
            {
                conn.Disconnect();
            }
' Define the Publisher, publication, and databases.
Dim publicationName As String = "AdvWorksProductTran"
Dim publisherName As String = publisherInstance
Dim subscriberName As String = subscriberInstance
Dim subscriptionDbName As String = "AdventureWorks2012Replica"
Dim publicationDbName As String = "AdventureWorks2012"

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

' Create the objects that we need.
Dim subscription As TransSubscription

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

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

    ' Delete the pull subscription, if it exists.
    If subscription.IsExistingObject Then

        ' Delete the pull subscription at the Subscriber.
        subscription.Remove()
    Else
        Throw New ApplicationException(String.Format( _
         "The subscription to {0} does not exist on {1}", _
         publicationName, subscriberName))
    End If
Catch ex As Exception
    ' Implement the appropriate error handling here.
    Throw New ApplicationException(String.Format( _
        "The subscription to {0} could not be deleted.", publicationName), ex)
Finally
    conn.Disconnect()
End Try

맨 위로 이동 링크와 함께 사용되는 화살표 아이콘[Top]

참고 항목

개념

게시 구독

복제 보안을 위한 최선의 구현 방법