Script to Enable/Disable Database for Replication


You can enable the database for replication using below script.

use master
exec sp_replicationdboption @dbname = 'sqldbpool',
@optname = 'publish',
@value = 'true'
go

If you have restore the database on test environment and you are getting the error that “Database is part of Replication”, you can clear/disable it by executing below query.

use master
exec sp_replicationdboption @dbname = 'sqldbpool',
@optname = 'publish',
@value = 'false'
go
Advertisements

4 thoughts on “Script to Enable/Disable Database for Replication

  1. saravanan R

    while i execute the above enable command , i am getting thebelow error

    OLE DB provider “SQLNCLI11” for linked server “repl_distributor” returned message “Login timeout expired”.
    OLE DB provider “SQLNCLI11” for linked server “repl_distributor” returned message “A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.”.
    Msg 53, Level 16, State 1, Line 0
    Named Pipes Provider: Could not open a connection to SQL Server [53].

    Reply
  2. Priyantha

    Jugal

    is there any possible way to enable and disable publication articles via PS and or SQL script without dropping publication. When I run the above it actually drops pub and renders in inaccessible.

    Reply

Thanks for the comment, will get back to you soon... Jugal Shah

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s