<Database> on <Server> contains user-defined schema. Databases must be empty before they can be used.
I ran into a strange problem today in SharePoint and thought I would share it with anyone else just in case you have the same issue.
I was in a SharePoint environment that was working as expected. I had a content database that had 8 site collections in it. I detached the database and then re-attached the exact same content database and received the following error message:
<database> on <server> contains user-defined schema. Databases must be empty before they can be used. Delete all of the tables, stored procedures and other objects or use a different database.
After a number of attempts, I could not get the database to add. I created a brand new content DB, detached, re-added it and received the exact same message.
I finally executed the stsadm addcontentdb command with the assignewdatabaseid and the error went away and the database was added successfully. The odd thing is the Current Number of Sites was now showing 0. I queried the sites table and saw the 8 sites in there so I knew everything was good.
I tried the clearing the SharePoint cache without success.
I finally found the root cause of the problem. It appears someone installed a SharePoint patch into the environment but never ran the configuration wizard. So although SharePoint was operating correctly, when re-attaching the database is knew something was run.
I executed the following command which applied the outstanding patch:
psconfig –cmd upgrade –inplace b2b –wait –force
After this, I was able to add and remove the content databases as I expected too without any issues.








