Skip to content

Latest commit

 

History

History
123 lines (75 loc) · 8.33 KB

delete-a-push-subscription.md

File metadata and controls

123 lines (75 loc) · 8.33 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic ms.custom helpviewer_keywords monikerRange
Delete a Push Subscription
Learn how to delete a push subscription in SQL Server by using SQL Server Management Studio, Transact-SQL, or Replication Management Objects.
MashaMSFT
mathoma
09/25/2024
sql
replication
how-to
updatefrequency5
removing subscriptions
push subscriptions [SQL Server replication], deleting
deleting subscriptions
subscriptions [SQL Server replication], push
=azuresqldb-current||>=sql-server-2016

Delete a Push Subscription

[!INCLUDEsql-asdb] This topic describes how to delete a push subscription in [!INCLUDEssnoversion] by using [!INCLUDEssManStudioFull], [!INCLUDEtsql], or Replication Management Objects (RMO).

In This Topic

Using SQL Server Management Studio

Delete a push subscription at the Publisher (from the Local Publications folder in [!INCLUDEssManStudioFull]) or the Subscriber (from the Local Subscriptions folder). Deleting a subscription does not remove objects or data from the subscription; they must be removed manually.

To delete a push subscription at the Publisher

  1. Connect to the Publisher in [!INCLUDEssManStudioFull], and then expand the server node.

  2. Expand the Replication folder, and then expand the Local Publications folder.

  3. Expand the publication associated with the subscription you want to delete.

  4. Right-click the subscription, and then click Delete.

  5. In the confirmation dialog box, select whether to connect to the Subscriber to delete subscription information. If you clear the Connect to Subscriber checkbox, you should connect to the Subscriber later to delete the information.

To delete a push subscription at the Subscriber

  1. Connect to the Subscriber in [!INCLUDEssManStudioFull], 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 delete, and then click Delete.

  4. In the confirmation dialog box, select whether to connect to the Publisher to delete subscription information. If you clear the Connect to Publisher check box, you should connect to the Publisher later to delete the information.

Using Transact-SQL

Push subscriptions can be deleted programmatically using replication stored procedures. The stored procedures used depend on the type of publication to which the subscription belongs.

To delete a push subscription to a snapshot or transactional publication

  1. At the Publisher on the publication database, execute sp_dropsubscription (Transact-SQL). Specify @publication and @subscriber. Specify a value of all for @article. (Optional) If the Distributor cannot be accessed, specify a value of 1 for @ignore_distributor to delete the subscription without removing related objects at the Distributor.

  2. At the Subscriber on the subscription database, execute sp_subscription_cleanup (Transact-SQL) to remove replication metadata in the subscription database.

To delete a push subscription to a merge publication

  1. At the Publisher, execute sp_dropmergesubscription (Transact-SQL), specifying @publication, @subscriber and @subscriber_db. (Optional) If the Distributor cannot be accessed, specify a value of 1 for @ignore_distributor to delete the subscription without removing related objects at the Distributor.

  2. At the Subscriber on the subscription database, execute sp_mergesubscription_cleanup (Transact-SQL). Specify @publisher, @publisher_db, and @publication. This removes merge metadata from the subscription database.

Examples (Transact-SQL)

This example deletes a push subscription to a transactional publication.

:::code language="sql" source="codesnippet/tsql/delete-a-push-subscription_1.sql":::

This example deletes a push subscription to a merge publication.

:::code language="sql" source="codesnippet/tsql/delete-a-push-subscription_2.sql":::

Using Replication Management Objects (RMO)

The RMO classes that you use to delete a push subscription depend on the type of publication to which the push subscription is subscribed.

To delete a push subscription to a snapshot or transactional publication

  1. Create a connection to the Publisher by using the xref:Microsoft.SqlServer.Management.Common.ServerConnection class.

  2. Create an instance of the xref:Microsoft.SqlServer.Replication.TransSubscription class.

  3. Set the xref:Microsoft.SqlServer.Replication.Subscription.PublicationName%2A, xref:Microsoft.SqlServer.Replication.Subscription.SubscriptionDBName%2A, xref:Microsoft.SqlServer.Replication.Subscription.SubscriberName%2A, and xref:Microsoft.SqlServer.Replication.Subscription.DatabaseName%2A properties.

  4. Set the xref:Microsoft.SqlServer.Management.Common.ServerConnection from step 1 for the xref:Microsoft.SqlServer.Replication.ReplicationObject.ConnectionContext%2A property.

  5. Check the xref:Microsoft.SqlServer.Replication.ReplicationObject.IsExistingObject%2A property to verify that the subscription exists. If the value of this property is false, either the subscription properties in step 2 were defined incorrectly or the subscription does not exist.

  6. Call the xref:Microsoft.SqlServer.Replication.Subscription.Remove%2A method.

To delete a push subscription to a merge publication

  1. Create a connection to the Publisher by using the xref:Microsoft.SqlServer.Management.Common.ServerConnection class.

  2. Create an instance of the xref:Microsoft.SqlServer.Replication.MergeSubscription class.

  3. Set the xref:Microsoft.SqlServer.Replication.Subscription.PublicationName%2A, xref:Microsoft.SqlServer.Replication.Subscription.SubscriptionDBName%2A, xref:Microsoft.SqlServer.Replication.Subscription.SubscriberName%2A, and xref:Microsoft.SqlServer.Replication.Subscription.DatabaseName%2A properties.

  4. Set the xref:Microsoft.SqlServer.Management.Common.ServerConnection from step 1 for the xref:Microsoft.SqlServer.Replication.ReplicationObject.ConnectionContext%2A property.

  5. Check the xref:Microsoft.SqlServer.Replication.ReplicationObject.IsExistingObject%2A property to verify that the subscription exists. If the value of this property is false, either the subscription properties in step 2 were defined incorrectly or the subscription does not exist.

  6. Call the xref:Microsoft.SqlServer.Replication.Subscription.Remove%2A method.

Examples (RMO)

You can delete push subscriptions programmatically by using Replication Management Objects (RMO).

[!code-csHowTo#rmo_DropTranPushSub]

[!code-vbHowTo#rmo_vb_DropTranPushSub]

Related content