> ## Documentation Index
> Fetch the complete documentation index at: https://rajanand.org/llms.txt
> Use this file to discover all available pages before exploring further.

# How to fix "This database is not enabled for publication" issue when the replication option is already enabled in SQL Server?

### Error 1:

> Msg 14013, Level 16, State 1, Procedure sp\_MSrepl\_addpublication, Line 188 This database is not enabled for publication.

### Error 2:

> Msg 14013, Level 16, State 1, Procedure sys.sp\_MSrepl\_addsubscription, Line 302 \[Batch Start Line 0] This database is not enabled for publication.

I was getting these errors on different occasions when trying to execute a script in a database to add a publication and add a subscription.

If the script is executed in a database that is not enabled for replication, then this error occurs.

### Solution:

To solve this issue, first, check whether the database is published.

```sql theme={"system"}
-- check database is published or not
select * from sys.databases where is_published=1
```

If not published, publish the database in the publisher server.

```sql theme={"system"}
--publish database
use publisher_database_name;
GO

exec sp_replicationdboption 
@dbname = N'publisher_database_name', 
@optname = N'publish', 
@value = N'true'
GO
```

Then, make sure you are connected to the published database. Execute your script. In my case, I have executed the add publication and add subscriptions. It has worked fine on both occasions. Hope this helps to solve your issue.
