Dennis van der Stelt

I care about technology; I care about users more

Community

Email Notifications

News

  • Addicted to Refactor! Pro
    <div class="sideNavItems">

I read...

I Use...

Tags

Recent Posts

Archives

Blog Subscription Form

  • Email Notifications
    Go

Cannot drop database because of replication

Wow it's been some time since I blogged. Mainly because of being very busy at work and three weeks of holidays. Next week I'll be offline again because Pascal, Alex and me will be preparing for the .NET 3.5 Summer Class in September. If you still don't know what it is, have a look at it and be sure to come. We'll teach you almost everything that's .NET 3.5 and you'll go home knowing what a great addition it is and how to build projects using it. This won't be a standard training, you will know how to use this stuff in your next projects.

Anyway, I was having some problems with dropping a database. It was the mirror of another one, mirrored by transaction log shipping. For some reason during my holidays and after some tweaking done by my client on more then one database, it failed. After having a look, some properties changed and not for the good. I decided to set it up again from scratch.

After removing transaction log shipping from the root database, I wanted to drop the database on the mirror server. Unfortunately I got the following error:

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

The jobs were gone, the root database wasn't attached anymore, but SQL Server 2005 still thought it was being used for replication. I even tried hacking the system tables using the dedicated administrator connection but it just wouldn't drop, delete, detach or anything.

Solution
The final solution was to create a new database on another server with the same name and create a backup. After copying the backup to the server with problems, I chose to restore the backup. You can't do this by right-clicking on the database, because it'll only allow to restore transaction logs. Right-click the server itself and choose to restore it onto the database with problems and select to "overwrite" in the options screen.

It overwrote the database and I could delete it!

Technorati Tags: ,

Comments

University Update-Microsoft SQL Server-Cannot drop database because of replication said:

Pingback from  University Update-Microsoft SQL Server-Cannot drop database because of replication

# August 3, 2007 3:06 PM

Rajkishore Gupta said:

Thanks

it was very helpful. since few days i was facing this issue.

# January 30, 2008 1:39 PM

Richard101 said:

Worked a treat with SQL2000, I backed-up secondary PUBS to disk then restored, changing the name.

# April 28, 2008 12:47 PM

ash said:

just wasted 3 hours and you helped me with a 2 second fix. Thanks

# May 15, 2008 8:39 PM

Lobelt said:

I faced the problem using SQL2000. Then I took the database offline without problems and I could delete the offline database. The data and log files had to be deleted manualy.

# September 12, 2008 2:49 PM

Sosh said:

This works.. Thanks for your help!

# September 21, 2008 2:02 PM

Suresh N said:

I have used different named database, of the same database having equal db structure worked fine.Hope this helps. You need not have to create a new database!

# October 28, 2008 7:34 PM

SQL Administrator said:

The simple solution for me was to take offline and delete the files. Thanks for the tip.

# October 31, 2008 2:28 PM

madhav said:

right click on local subscriptions and click on subscripton properties in the right pane click on publication databases and unmark all the databases that are being used

# May 26, 2009 1:22 PM

WINNT said:

You can also type:

use master

exec sp_removedbreplication YourDatabaseName

go

# July 9, 2009 11:41 PM

Andrew said:

Thanks I spent 2 hours trying to remove a database that's replication partner no longer existed for. Your soultion worked. You rock!

# August 11, 2009 10:02 PM

Mostafa Darabi said:

Thanks a lot

# February 18, 2010 3:13 PM

Mostafa Darabi said:

Thanks for your help.

# February 18, 2010 3:15 PM

Pranita said:

Thanx....

exec sp_removedbreplication works..

# March 9, 2010 8:06 AM

Noravia Rodriguez - City Of Miami - Database Manager said:

Autor      :             Noravia Rodriguez

Date        :             03/02/2010

Updates:             03/16/2010

Purpose:              How to unmark a database marked as replicated in SQL Server 2005

How to unmark a database marked as replicated in SQL Server 2005

1. Try:

EXEC sp_removeddbreplication “”DatabaseName”

GO

2. Try:

Take Database OffLine

Deatch

Attach Database Back

3. This tasks need to be done MANUALLY and in the following order:

i. Drop all existing subscriptions

ii. Drop all existing pubications

iii. Create a new publications with the same name

iv. Drop it again and say “Yes” to delete information on the Distributor (Distribution Database)

v. Verify Database has been unmark for replication

1. Go to the Database-Tasks-Detach and ensure that mark has been removed

OR

2. Run the following query and ensure “Category”=0           (RECOMMENDED)

SELECT name,category,* FROM master..sysdatabases

# March 16, 2010 5:51 PM

Noravia Rodriguez said:

SQL Server 2000

a. Database

use master

GO

exec sp_replicationdboption @dbname = N'dbPOMS', @optname = N'publish', @value = N'false'

GO

b. Columns

use master

GO

exec sp_replicationdboption @dbname = N'dbPOMS', @optname = N'publish', @value = N'false'

GO

use [dbPOMS]

GO

sp_configure 'allow updates', 1

go

reconfigure with override

go

-- For Tables

UPDATE syscolumns SET colstat = colstat & ~4096 WHERE colstat & 4096 <>0

go

-- For columns

UPDATE sysobjects SET repinfo=0 where repinfo=1

Go

sp_configure 'allow updates', 0

go

reconfigure with override

go

# March 16, 2010 6:04 PM

Mohmmed said:

Was very helpful, it was a simple solution but no 1 usually tends to think on that side....

And you did so you are the 1 :)......

And about above comments removedb replication and all that it wont work if logshipping is broken and morever if ur missing the *.tuf file......

Please read the post before you all answer and make people go in wrong directions......

And also its next to impossible at times to update sys tables even with DAC connections.....

Anyways Nice post ......

Thanks

# December 7, 2010 6:19 PM

Loke said:

It woked just perfect!!!!

# July 18, 2011 11:49 PM

Junaid Siddiqui said:

Please use this script to remove table value from sys.tables:

-- Removes Replication Flag for all Tables in the Database

-- using sp_MSunmarkreplinfo

SET NOCOUNT ON

DECLARE @tablename NVARCHAR(128)

DECLARE @RC INT

DECLARE curTable CURSOR FOR

SELECT [name] AS tbl

FROM sys.tables

OPEN curTable

FETCH NEXT FROM curTable

INTO @tablename

WHILE @@FETCH_STATUS = 0

BEGIN

EXECUTE @RC = dbo.sp_MSunmarkreplinfo @tablename

FETCH NEXT FROM curTable

INTO @tablename

END

CLOSE curTable

DEALLOCATE curTable

GO

# November 22, 2011 3:54 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Please add 7 and 4 and type the answer here: