SQL SERVER – FIX – ERROR : Cannot drop the database because it is being used for replication. (Microsoft SQL Server, Error: 3724)

I have set up replication at many different organization. One error I quite commonly face is after I have removed replication I can not remove database. When I try to remove the database it gives me following error. Here is the simple fix I use for Error 3724. The message says the database cannot be dropped because it is being used for replication.

Cannot drop the database because it is being used for replication. (Microsoft SQL Server, Error: 3724)

Fix/Workaround/Solution:

The solution is very simple. Create the empty database with the same name on another server/instance first. Take full back of the same and forced restore over this database.

Restore Database Options.

Do let me know if you have any better idea or suggestion.

What to Check When a Database Used for Replication Won’t Drop

Before you try any workaround, find out what SQL Server still believes about the database. The replication flags live in sys.databases. Look at the is_published, is_subscribed, is_merge_published and is_distributor columns. If any of them shows 1, some replication setting is still attached, even after you removed the publication. It takes a few seconds and tells you where to look.

A cleaner route than backup and restore is the system procedure sp_removedbreplication. You pass it the database name, and it removes the replication objects from that database. In many cases the drop goes through right after that. Run it on the correct instance, because it does exactly what its name says. If only the publish flag is stuck, sp_replicationdboption with the publish option set to false can switch it off as well.

A few mistakes I have seen more than once:

  • Dropping the database before removing the subscriptions and publications in the proper order.
  • Forgetting that the restore trick overwrites everything in that database. If there is any chance you need the data, take a real backup first.
  • Running the cleanup on the wrong server. On a busy day, check @@SERVERNAME before you press F5.

Once the database is gone, open SQL Server Agent and look for any leftover replication jobs that still point to it. Old jobs that fail every night only add noise to your alerts.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL Error Messages, SQL Replication, SQL Scripts
Previous Post
PERCENTILE_DISC: Return an Observed Percentile Value
Next Post
SQL SERVER – Find Gaps in The Sequence

Related Posts

41 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.