events
3月31日 23時 - 4月2日 23時
最大の SQL、Fabric、Power BI 学習イベント。 3 月 31 日から 4 月 2 日。 コード FABINSIDER を使用して $400 を保存します。
今すぐ登録このブラウザーはサポートされなくなりました。
Microsoft Edge にアップグレードすると、最新の機能、セキュリティ更新プログラム、およびテクニカル サポートを利用できます。
適用対象: SQL Server
Azure SQL データベース
このトピックでは、SQL Server Management Studio、Transact-SQL、または レプリケーション管理オブジェクト (RMO) を使用して、SQL Server でプッシュ サブスクリプションを削除する方法について説明します。
このトピックの内容
プッシュ サブスクリプションを削除するために使用するもの:
パブリッシャーまたはサブスクライバーで、プッシュ サブスクリプションを削除します (SQL Server Management Studioの場合は の [ローカル パブリケーション] フォルダーから、サブスクライバーの場合は [ローカル サブスクリプション] フォルダーから削除します)。 サブスクリプションを削除しても、サブスクリプションのオブジェクトやデータは削除されません。これらは手動で削除する必要があります。
SQL Server Management Studio でパブリッシャーに接続し、サーバー ノードを展開します。
[レプリケーション] フォルダーを展開し、 [ローカル パブリケーション] フォルダーを展開します。
削除するサブスクリプションに関連付けられているパブリケーションを展開します。
サブスクリプションを右クリックし、 [削除]をクリックします。
確認のダイアログ ボックスで、サブスクライバーに接続してサブスクリプション情報を削除するかどうかを選択します。 [サブスクライバーへの接続] チェック ボックスをオフにした場合は、後でサブスクライバーに接続してこの情報を削除する必要があります。
SQL Server Management Studio でサブスクライバ―に接続し、サーバー ノードを展開します。
[レプリケーション] フォルダーを展開し、 [ローカル サブスクリプション] フォルダーを展開します。
削除するサブスクリプションを右クリックし、 [削除]をクリックします。
確認のダイアログ ボックスで、パブリッシャーに接続してサブスクリプション情報を削除するかどうかを選択します。 [パブリッシャーへの接続] チェック ボックスをオフにした場合は、後でパブリッシャーに接続してこの情報を削除する必要があります。
プッシュ サブスクリプションは、レプリケーション ストアド プロシージャを使用してプログラムで削除できます。 使用するストアド プロシージャは、サブスクリプションが属するパブリケーションの種類によって異なります。
パブリッシャー側のパブリケーション データベースに対して、sp_dropsubscription (Transact-SQL) を実行します。 @publication と @subscriberを指定します。 @article に allを指定します。 (省略可) ディストリビューターにアクセスできない場合、 @ignore_distributor に 1 を指定して、ディストリビューターの関連オブジェクトを削除せずにサブスクリプションを削除します。
サブスクライバー側のサブスクリプション データベースで sp_subscription_cleanup (Transact-SQL) を実行して、サブスクリプション データベース内のレプリケーション メタデータを削除します。
パブリッシャー側で、@publication、@subscriber、@subscriber_db を指定して、sp_dropmergesubscription (Transact-SQL) を実行します。 (省略可) ディストリビューターにアクセスできない場合、 @ignore_distributor に 1 を指定して、ディストリビューターの関連オブジェクトを削除せずにサブスクリプションを削除します。
サブスクライバー側のサブスクリプション データベースに対して、sp_mergesubscription_cleanup (Transact-SQL) を実行します。 @publisher、 @publisher_db、および @publicationを指定します。 これにより、サブスクリプション データベースのマージ メタデータが削除されます。
この例では、トランザクション パブリケーションへのプッシュ サブスクリプションを削除します。
-- 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 クラスは、プッシュ サブスクリプションをサブスクライブするパブリケーションの種類によって異なります。
ServerConnection クラスを使用して、パブリッシャーへの接続を作成します。
TransSubscription クラスのインスタンスを作成します。
PublicationName、 SubscriptionDBName、 SubscriberName、 DatabaseName の各プロパティを設定します。
手順 1. の ServerConnection を ConnectionContext プロパティに設定します。
IsExistingObject プロパティをチェックして、サブスクリプションが存在することを確認します。 このプロパティの値が falseの場合、手順 2. でサブスクリプション プロパティが不適切に定義されたか、サブスクリプションが存在していません。
Remove メソッドを呼び出します。
ServerConnection クラスを使用して、パブリッシャーへの接続を作成します。
MergeSubscription クラスのインスタンスを作成します。
PublicationName、 SubscriptionDBName、 SubscriberName、 DatabaseName の各プロパティを設定します。
手順 1. の ServerConnection を ConnectionContext プロパティに設定します。
IsExistingObject プロパティをチェックして、サブスクリプションが存在することを確認します。 このプロパティの値が falseの場合、手順 2. でサブスクリプション プロパティが不適切に定義されたか、サブスクリプションが存在していません。
Remove メソッドを呼び出します。
レプリケーション管理オブジェクト (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
events
3月31日 23時 - 4月2日 23時
最大の SQL、Fabric、Power BI 学習イベント。 3 月 31 日から 4 月 2 日。 コード FABINSIDER を使用して $400 を保存します。
今すぐ登録トレーニング
モジュール
Dynamics 365 Customer Insights - Journeys でサブスクリプション センターとダブル オプトインを管理する - Training
Dynamics 365 Customer Insights - Journeys でのサブスクリプション センターとダブル オプトインの管理について説明します。 このモジュールは、アウトバウンド マーケティング機能にのみ適用されます。
ドキュメント
プル サブスクリプションの削除
SQL Server Management Studio、Transact-SQL、またはレプリケーション管理オブジェクトを使用して SQL Server のパブリケーションを削除する方法について説明します。
sp_droppublication (Transact-SQL) - SQL Server
パブリケーションおよびこれと関連するスナップショット エージェントを削除します。 このストアド プロシージャは、パブリッシャー側のパブリケーション データベースで実行されます。