如何:停用發行和散發 (複寫 Transact-SQL 程式設計)

您可以使用複寫預存程序來以程式設計的方式停用發行和散發。

停用發行和散發

  1. 停止所有複寫相關的作業。如需作業名稱清單,請參閱<複寫代理程式安全性模型>一節中的「SQL Server Agent 下的代理程式安全性」。

  2. 在訂閱資料庫的每一個訂閱者上,執行 sp_removedbreplication 從資料庫中移除複寫物件。這個預存程序將不會移除散發者上的複寫作業。

  3. 在發行集資料庫的發行者上,執行 sp_removedbreplication 從資料庫中移除複寫物件。

  4. 如果發行者使用遠端散發者,請執行 sp_dropdistributor

  5. 在散發者上執行 sp_dropdistpublisher。應該針對散發者上註冊的每一個發行者執行此預存程序一次。

  6. 在散發者上,執行 sp_dropdistributiondb 來刪除散發資料庫。應該針對散發者上的每一個散發資料庫執行此預存程序一次。這樣也會移除與散發資料庫有關的任何佇列讀取器代理程式作業。

  7. 在散發者上,執行 sp_dropdistributor 從伺服器移除散發者的指定。

    [!附註]

    如果在您執行 sp_dropdistpublishersp_dropdistributor 之前,尚未卸除所有複寫發行和散發物件,這些程序將會傳回錯誤。若要在卸除了發行者或散發者時,一併卸除所有複寫相關的物件,@no_checks 參數必須設定為 1。如果發行者或散發者已離線或是無法連上,@ignore_distributor 參數可以設定為 1,好讓它們可以卸除;但是,必須手動移除任何留下來的發行和散發物件。

範例

這個範例指令碼會從訂閱資料庫中移除複寫物件。

-- Remove replication objects from the subscription database on MYSUB.
DECLARE @subscriptionDB AS sysname
SET @subscriptionDB = N'AdventureWorks2008R2Replica'

-- Remove replication objects from a subscription database (if necessary).
USE master
EXEC sp_removedbreplication @subscriptionDB
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".

-- Disable publishing and distribution.
DECLARE @distributionDB AS sysname;
DECLARE @publisher AS sysname;
DECLARE @publicationDB as sysname;
SET @distributionDB = N'distribution';
SET @publisher = $(DistPubServer);
SET @publicationDB = N'AdventureWorks2008R2';

-- Disable the publication database.
USE [AdventureWorks2008R2]
EXEC sp_removedbreplication @publicationDB;

-- Remove the registration of the local Publisher at the Distributor.
USE master
EXEC sp_dropdistpublisher @publisher;

-- Delete the distribution database.
EXEC sp_dropdistributiondb @distributionDB;

-- Remove the local server as a Distributor.
EXEC sp_dropdistributor;
GO