Monday, October 29, 2012

Delete sites with "Internal server error" messages

I inherited permissions on a site the other day and boom! Got an Error message and then.... the site got the annoying "500 Internal server error" and was no longer accessible. Great. No immediate cause in the log files, though scanned them up and down. Enabled custom errors in web.config and got this error:
"The DataSourceID of 'TopNavigationMenuV4' must be of the ID of a control of type IHierarchicalDataSource. A control with ID 'topSiteMap' could not be found."


Wow. What the hell is that. Googled it and found a SQL query you could run in your db to fix this. But that only ended up in "0 rows affected" so no luck. I guess there were more errors than just this...
 
Tried all possible ways to access the sites like adding _layouts/settings.aspx, adding ?contents=1 after welcome.aspx, opened Manage content and structure but the site was not listed there, opened Site Settings and Site hierarchy and clicked on Manage (strangely enough the link to the site and subsites was still in there) but all I got was the "Internal server error" message.
I googled to death to find a solution but there seemed to be none that worked for me. But found this article on MS that this is a known issue: http://support.microsoft.com/kb/937038. But that is for MOSS and we are on SP2010 so did not dare apply that.

Seemed like the only solution was to restore the site.
But I could not restore it back to its original place since the sites were still there... even if I tried the force command I could not overwrite the sites (using the Import-SPWeb and -force). Error in Powershell was cannot find an spweb object with ID or URL...
Could not delete the site through Powershell command delete either (Remove-SPWeb). Same error in powershell as above.

Finally found a command that worked though and that is run through STSADM in Powershell:

1) First enum all sites stsadm -o enumallwebs -databasename WSS_YourDBname
2) Then you need to find out what GUID the db's has (I usually export them to a txt file for easy copy)
Get-SPWebApplication "http://spserver/" | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Title, ID, URL | out-file d:\webs.txt | format-table -auto
3) In Powershell enter this command
stsadm -o deleteweb -force -webid "GUID" -databaseserver yourdbserver\instancename -databasename WSS_YourDBname

This will delete the sites.
Some of these deletions can take a looong time. But just leave it running, do not interrupt it.