Friday, January 22, 2010

Cannot drop the database 'MyDatabase' because it is being used for replication. [SQLSTATE 42000] (Error 3724)

I wanted to drop and restore a database which I restored couple days ago in a test environment. The same db in production is the publisher and there are objects in transactional replication. I was asked to restore the new backup. However drop database returned the error message in the subject line and did not drop the db. Little bit of searching and I found out that the stored procedure can be used to remove the replication prior to dropping the database in test environment. So I connected to my test server and executed following statements in the order.

1. USE MASTER EXEC dbo.sp_removedbreplication @dbname = 'MyDatabase'
2. USE MASTER DROP DATABASE MyDatabase

It worked and I was able to drop and restore the latest backup to the test environment.

Do not run this in production since it will remove the replication from your production publisher.

HTH,

5 comments:

  1. Thank you very much it is worked for me........

    ReplyDelete
  2. Replies
    1. Are you getting the same error message, can you tell me about the problem, and send me the error message?

      Delete