This had me pulling my hair out today (and there's not too much left, believe me). I was so frustrated, but finally hope smiled down on my endeavors.
I had a SQL Server database that I was trying to drop (either via Enterprise Manager or via the script DROP DATABASE 'xxx'). Each time I tried, it would fail with the error message:
Error 3724: Cannot drop the database 'xxx' because it is being used for replication
This was disconcerting because I no longer had replication enabled on the server. I tried all of the recommendations that I could find online to remove any association of replication from the database, and they all failed for me though they had worked for others. For instance, the most frequently recommended strategy that I found was this:
sp_replicationdboption 'xxx', 'publish', FALSE
GO
sp_replicationdboption 'xxx', 'merge publish', FALSE
GO
or
sp_removedbreplication 'xxx'
GO
Once again, I could not successfully delete the database following these actions. I simply could not see a way to remove the database. Then a coworker had a stroke of genius that I'd like to share.
He suggested the following and it worked like a charm:
- Create a dummy, temp database called 'Hope' (we called it that because we hoped it would work).
- Backup the database.
- Restore the backup over the database you can't delete (you'll have to rename the target file so as to not conflict with your original, dummy, temp database).
- Happily delete both databases
That got rid of it. Boy what a hassle.
Can any of you DBA's out there think of something else that I haven't tried? Does this approach make you cringe? I battled it for the better part of 2 hrs before resorting to this approach and simply couldn't get anything else to work.