Archive

Archive for the ‘Central Administration’ Category

SharePoint – An unexpected error has occurred or Object Reference Error in a site collection after reattaching a Content Database

2013/02/16 2 comments

After removing a content database from a SharePoint 2010 web application, so that I can restore a backup (for development purposes), upon reattaching the content database I was being plagued with an assortment of error message.

These included when trying to load the site, seeing both an “An unexpected error has occurred” and a simple server information block returned, and upon checking the logs seeing:

“System.NullReferenceException: Object reference not set to an instance of an object.    at Microsoft.SharePoint.SPSite.PreinitializeServer(SPRequest request)”

This would occur on a single web front end server in the development farm (yep, I have multiple WFEs in my development environment), while the other WFEs would load fine.

After a couple different investigations, I found out that one cause of single server site corruption after reattaching a SP content db is… it’s the PowerShell SharePoint CmdLets.

If you are running PowerShell and are using the SharePoint CmdLets (SPSite for example) to connect to that site (for the content database in question), if you try to reattach the content database while that PowerShell session is still open, the reattach goes fine, but the servers where PowerShell was open will fail load the site thereafter… even after reboots and all.

You need to close the PowerShell window and then reattach the content database (either by the Central Admin UI or from a new PowerShell window if you are using scripts).

Additionally, the W3SVC and SPADMIN and SPTIMER services can all cause the same problem, so I have found that restarting those also (I bundled it up into a single PowerShell cmdlet) ensures that I never saw this issue again.