0

我在其中使用 sql server 2012 和复制过程。现在复制过程正常工作,但我想删除此复制,我的意思是通过脚本的所有出版物、订阅和文章。我浏览了这个网站http://support.microsoft.com/kb/324401并尝试了以下脚本

:setvar PublisherDatabase "AdventureWorks2012"
:setvar SubscriberServer "HYDHTC0131320D\MSSQLSERVER2"

use [$(PublisherDatabase)]

--Drop all subscriptions
exec sp_dropsubscription  
@publication = N'TestPubs',
@article = N'all',
--@subscriber = [$(SubscriberServer)]
@subscriber = N'all',
@destination_db = N'all'

--Drop publication
if exists (Select 1 From SysPublications where name = N'TestPubs')
EXEC sp_droppublication @publication = N'TestPubs'

EXEC sp_replicationdboption @dbname = [$(PublisherDatabase)], @optname = N'publish', @value = N'false'

--Drop subscriber entry
EXEC sp_dropsubscriber @subscriber = [$(SubscriberServer)]

--Drop distributor
EXEC sp_dropdistributor @no_checks = 1

在我执行上述脚本后,我收到以下错误。

Only one Log Reader Agent or log-related procedure (sp_repldone, sp_replcmds, and sp_replshowcmds) can connect to a database at a time. If you executed a log-related procedure, drop the connection over which the procedure was executed or execute sp_replflush over that connection before starting the Log Reader Agent or executing another log-related procedure.

Msg 18752, Level 16, State 1, Procedure sp_replcmds, Line 1

Only one Log Reader Agent or log-related procedure (sp_repldone, sp_replcmds, and sp_replshowcmds) can connect to a database at a time. If you executed a log-related procedure, drop the connection over which the procedure was executed or execute sp_replflush over that connection before starting the Log Reader Agent or executing another log-related procedure.

The Subscriber was dropped.

Msg 20015, Level 16, State 1, Procedure 

sp_MSreplremoveuncdir, Line 83
Could not remove directory 'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\ReplData\unc\HYDHTC0131320D_ADVENTUREWORKS2012_TESTPUBS\20120719152739\'. Check the security context of xp_cmdshell and close other processes that may be accessing the directory.

查看此屏幕截图以获取更多详细信息

在此处输入图像描述

谁能帮我解决这些问题

4

2 回答 2

2

看起来您在删除复制时遇到了一些错误,并且在订阅者处有一些孤立的订阅元数据。可以使用sp_removedbreplication从订阅数据库中删除孤立的元数据。

为了将来参考,您可以按照以下步骤删除所有订阅、发布并禁用发布和分发:

链接中的相关代码位

a) 删除事务复制的推送订阅

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

b) 删除合并复制的订阅

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

c) 在事务复制中删除发布并将源数据库设置为停止成为发布者。

DECLARE @publicationDB AS sysname;
DECLARE @publication AS sysname;
SET @publicationDB = N'AdventureWorks2008R2'; 
SET @publication = N'AdvWorksProductTran'; 

-- Remove a transactional publication.
USE [AdventureWorks2008R2]
EXEC sp_droppublication @publication = @publication;

-- Remove replication objects from the database.
USE [master]
EXEC sp_replicationdboption 
  @dbname = @publicationDB, 
  @optname = N'publish', 
  @value = N'false';
GO

d) 在合并复制中删除发布并将源数据库设置为停止成为发布者。

DECLARE @publication AS sysname
DECLARE @publicationDB    AS sysname
SET @publication = N'AdvWorksSalesOrdersMerge' 
SET @publicationDB = N'AdventureWorks2008R2'

-- Remove the merge publication.
USE [AdventureWorks2008R2]
EXEC sp_dropmergepublication @publication = @publication;

-- Remove replication objects from the database.
USE master
EXEC sp_replicationdboption 
  @dbname = @publicationDB, 
  @optname = N'merge publish', 
  @value = N'false'
GO
于 2012-07-21T22:55:10.313 回答
0

我的解决方法是sp_droppublication在事务中做。

-- local variables
declare
 @return_code    int -- return code of sp
,@dependent_publ sysname -- publication dependent on replicated RDZ tables

declare a cursor for
select distinct p.name from syspublications p
 inner join sysarticles s on p.pubid = s.pubid 
 inner join adm_replicated_rdz_tables r on r.table_name = s.name

if exists
 (select * from sys.objects
   where object_id = object_id('[dbo].[sysarticles]') and type in ('U'))
begin
 open a; fetch next from a into @dependent_publ; while @@fetch_status = 0
 begin
  begin transaction
   print @dependent_publ
   execute sp_droppublication @dependent_publ;
  commit
  fetch next from a into @dependent_publ;
 end; close a; deallocate a;
end
于 2013-10-04T10:15:36.233 回答