Say I've got replication on a SQL Server 2012 box set up. Everything is working as expected, and the Log Reader Agent is running.
Now, say that I need to remove all traces of this publication/subscription from the database programmatically. Previously, I had this working with SQL 2008R2.
The steps I was taking are -
- Drop subscription at source database (sp_dropsubscription)
- Drop subscription at target database (sp_droppullsubscription)
- Drop publisher (sp_droppublication)
- Remove everything else (sp_replicationdboption)
- Remove databases
This used to work perfectly, but since upgrading to SQL 2012, when I try to drop the publisher, I get the following error -
System.Data.SqlClient.SqlException (0x80131904): 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.
Now, I think I understand what's going on here, but I don't know how to prevent it.
What's the best way of stopping the Log Reader Agent, either via command line, or via SQL?