Sunday, November 28, 2010

Restore Database who was replicate

How many times we need to restore database into Dev or Test environnement?

The problem is when a databse is replicate and we restore it into an other environnement, the status of database not change. When we try to clear the transaction log, we get an error about some transaction is still open for replication.

Here is the step to resolve this issue:

Exec sp_replicationdboption @dbname = N'your db name', @optname= N'publish', @value= N'true'

Exec sp_repldone @xactid=NULL, @xact_segno=NULL, @numtrans = 0, @time=0 @reset=1

(
Exec sp_replicationdboption @dbname = N'your db name', @optname=N'publish', @value=N'false'

AND / OR

Exec sp_replicationdboption @dbname = N'your db name', @optname=N'subscribe',@value=N'false'
)


Exec sp_removedbreplication 'your db name'

DBCC opentran('your db name') -- to be sure you don't have any transaction open

kind of action you can do now

backup log 'your db name' with truncate_only

No comments: