밀어넣기 구독 삭제

적용 대상:SQL ServerAzure SQL Database

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

항목 내용

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. 확인 대화 상자에서 구독 정보를 삭제하기 위해 게시자에 연결할지 여부를 선택합니다. 게시자 검사 상자에 대한 커넥트 지우면 나중에 게시자에 연결하여 정보를 삭제해야 합니다.

Transact-SQL 사용

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

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

  1. 게시 데이터베이스의 게시자에서 sp_dropsubscription(Transact-SQL)를 실행합니다. @publication@subscriber를 지정합니다. @articleall값을 지정합니다. (선택 사항) 배포자에 액세스할 수 없는 경우 배포자에서 관련 개체를 제거하지 않고 구독을 삭제하려면 @ignore_distributor 값 1 을 지정합니다.

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

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

  1. 게시자에서 @publication, @subscriber 및 @subscriber_db 지정하여 sp_dropmergesubscription(Transact-SQL)를 실행합니다. (선택 사항) 배포자에 액세스할 수 없는 경우 배포자에서 관련 개체를 제거하지 않고 구독을 삭제하려면 @ignore_distributor 값 1 을 지정합니다.

  2. 구독 데이터베이스의 구독자에서 sp_mergesubscription_클린up(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 [AdventureWorks2022]
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'AdventureWorks2022Replica';

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

RMO(복제 관리 개체) 사용

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

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

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

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

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

  4. 속성에 ServerConnection 대해 1단계에서 설정합니다 ConnectionContext .

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

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

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

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

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

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

  4. 속성에 ServerConnection 대해 1단계에서 설정합니다 ConnectionContext .

  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 = "AdventureWorks2022Replica";
string publicationDbName = "AdventureWorks2022";

//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 = "AdventureWorks2022Replica"
Dim publicationDbName As String = "AdventureWorks2022"

'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

참고 항목

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