I was trying to restore a database, but was getting this error.
Error in text is, “the database principal is set as the execution context of one or more procedures functions.”
Error is getting after completion of 100% and after searching few web pages, it seems like a security or schema error. These are few of those links.
However, none of these links were relevant after I verify all schemas.
Then there was thought came to check the error logs and found this error in the error log.
Database 'XXXX' 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 is the BOL link for it. http://msdn.microsoft.com/en-us/library/ms151782(v=sql.90).aspx
This error is raised if a problem occurs restoring a backup of a replicated database:
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.
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.
Also, you can restore the database with KEEP_REPLICATION option as well.