How to delete SQL server replication

CFS_developer
CFS_developer used Ask the Experts™
on
On SQL Server 2008 R2, I am trying to setup transactional replication with test data and I'm getting an error:  
SQL Server could not create publication PubOne.
Database 'distribution' does not exist.  

This probably occurs because I previously tried to setup replication,
dropped my test databases, dropped distribution, and started over.

How do I fix this mess and truly start over?  


Here's what I tried to delete replication:

alter database ReplicationSource set offline
alter database ReplicationTarget set offline
alter database distribution      set offline
go

drop database ReplicationSource -- and remove disk files
drop database ReplicationTarget -- and remove disk files
drop database distribution      -- and remove disk files
go

exec sp_removeDbReplication 'ReplicationSource'
exec sp_removeDbReplication 'ReplicationTarget'
go

exec sp_dropdistributor   -- fails with    Could not drop the Distributor 'DAVIDZ-PC'. This Distributor has associated distribution databases.
go
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Vitor MontalvãoIT Engineer
Distinguished Expert 2017
Commented:
Did you follow this MSDN article?
Jason clarkDBA Freelancer
Commented:
sp_removedbreplication

This procedure should be used only if other methods of removing replication objects have failed. For more information about these methods.

To know more click on this https://technet.microsoft.com/en-us/library/ms152757(v=sql.105).aspx
Gentlemen,

The procedures you cite would have been great if I started with them.  Unfortunately, I didn't know what I was doing, so I just dropped all relevant databases (distribution, replication source, replication target).  But now the database server thinks replication is still going.  How do I finally kill replication and start over?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Vitor MontalvãoIT Engineer
Distinguished Expert 2017
Commented:
Check if the query returns any '1' for the columns. If it does you need to update it to zero (0):
SELECT name, is_distributor, is_publisher, is_subscriber
FROM master.sys.servers

Open in new window

Victor,

I found 3 commands which seemed to do the trick:
 
  exec sp_dropDistPublisher @publisher='MyPublisherName', @no_checks=1, @ignore_distributor=1
  exec sp_dropDistributionDb distribution
  exec sp_dropDistributor @ignore_distributor=1

I also executed your query and all columns came back as zero.  I think it might even be fixed!
IT Engineer
Distinguished Expert 2017
Commented:
Great. Those check and ignore parameters might did the trick.

Author

Commented:
My input provided part of the solution

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial