im using sql server 2012 and replication process in it. now the replication process is working correctly, but i want to delete this replication, i mean all the publications, subscriptions and articles through script. i went through this site http://support.microsoft.com/kb/324401 and tried the following script
: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
after i execute the above script, im getting the following error.
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.
check this screenshot for more details
can anyone help me in solving these issues