Avoid running Mount-SPContentDatabase using the same database name in a single PowerShell window. You'll likely only run into this if you are doing some upgrade testing, but it was driving me insane today, so wanted to share:
- Backup your SharePoint 2007 Content Database
- Open the SharePoint 2010 Management Shell
- Run: Mount-SPContentDatabase
- Hit enter, then fill in the name of the database and the web app you want to attach the database to
- Upgrade completes successfully, the world is a happy place
- Leave the PowerShell window open
You start messing with some customized sites and end up breaking one after doing the visual upgrade. You want to start over with a clean upgrade on the database.
- Detach the content database from the SharePoint 2010 web application
- Delete the database from SQL Server
- Restore the backup
- In the existing PowerShell window, run Mount-SPContentDatabase again
- Upgrade fails 🙁
You check out the upgrade file in the \14\Logs folder and there are some errors stating that upgrade did not occur on your site collections. At first, the only errors seemed related to the Basic Meeting Workspace site:
[SPWebTemplateSequence] [ERROR]: Template MPS#0: SPWeb Id=f1c7b33e-ccf1-4c6c-b0ac-947d678a693a could not be accessed in SPSite Id=d587100d-220e-4732-8bff-ab765f377806 due to exception. Skipping this SPWeb for template upgrade. Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.SharePoint.SPSite.PreinitializeServer(SPRequest request)
at Microsoft.SharePoint.SPSite.OpenWeb(Guid gWebId, Int32 mondoHint)
at Microsoft.SharePoint.Upgrade.SPWebTemplateSequence.ActivateWebFeatures(List`1 lstwebinfoToUpgrade, List`1& lstsiteidExceptions, List`1& lstwebinfoExceptions)
I did some further testing and created a site collection using each of the templates and reproduced again. This time I noticed all the site collections were failing to upgrade. All of them failing with a NullReferenceException. The Blank Meeting Workspace [MPS#0] was failing with the above stack, but the others were more subtle:
CanUpgrade [SPSite Url=http://jormanweb05/sites/blog] failed.
Exception: Object reference not set to an instance of an object.
Note: Removed the date/time and extra info from the log entry.
After a bit of troubleshooting, I found that as long as I open a new PowerShell window to run Mount-SPContentDatabase, the upgrade was consistently working.