Product Build Number
SQL Server Database Engine
Database '%ls' was restored; however, an error was encountered while replication was being restored/removed. The database has been left offline. See the topic MSSQL_ENG003165 in SQL Server Books Online.
This error is raised if a problem occurs restoring a backup of a replicated database:
If the backup is being restored to the same database and server on which it was taken, the error indicates that replication settings could not be restored properly.
If the backup is being restored to a different database or server, the error indicates that replication settings could not be removed properly (by default, replication settings are removed if the database or server is different).
The error is probably the result of a mismatch between the state of the restored database and one or more system databases that contain replication metadata: msdb, master, or the distribution database.
To resolve this issue:
Execute ALTER DATABASE to bring the database online; for example: ALTER DATABASE AdventureWorks SET ONLINE. For more information, see ALTER DATABASE (Transact-SQL). If you want to preserve replication settings, go to step 2. If not, go to step 3.
Execute sp_restoredbreplication (Transact-SQL). If this stored procedure executes successfully, the restore is complete. If it does not execute successfully, go to step 3.
Execute sp_removedbreplication (Transact-SQL) to remove all replication settings.
Reconfigure replication if necessary. If you have scripted the replication topology as recommended, use scripts to reconfigure the topology.