Resolving an Error When Deleting a SharePoint Web Application Caused by Orphaned Databases

I recently encountered a frustrating SharePoint issue that I hadn't seen in many years and had almost forgotten about. It's a rare problem, but it resurfaced while I was configuring a new SharePoint Subscription Edition farm: I was unable to delete a web application, neither through Central Administration nor with PowerShell:

Remove-SPWebApplication : An object in the SharePoint administrative framework, "SPWebApplication Name=sp-wfe.sps.local", could not be deleted because other objects depend on it.  Update all of these dependants to point to null or different objects and retry this operation.  The dependant objects are as follows: At line:1 char:1

The root cause of this error isn't clear, and the usual troubleshooting steps are ineffective. I tried finding the associated timer job, restarting all SPTimerV4 and SPAdminV4 services, running IISRESET on all SharePoint servers in the farm, and even rebooting all the servers. There were no "other objects depend on it" as far as I can see. The issue remained.

The problem lies with a corrupted content database that needs to be cleaned up. As you can see below, when you run Get-SPContentDatabase, nothing is returned. However, when you run Get-SPDatabase, it reveals the database of type "Content Database" (you can ignore the SpFarmAdmin database, as that is for the content DB of Central Admin):


Corrupted Content Database Found with Get-SPDatabase

Another way to check the orphaned status is by running the Get-SPSite command. The output will show no value for the CompatibilityLevel column for the affected site (in this case, the top-level site collection):

Get-SPSite returns no CompatibilityLevel value

The solution is to delete the orphaned database. You can do this by calling the Delete() method after obtaining the database by its ID (screenshot above). Once the orphaned databases are removed, the Remove-SPWebApplication command should run successfully:





Comments

Popular posts from this blog

October 2025 SharePoint CU Failed to Install After Applying September 2025 SharePoint CU

SharePoint Subscription Edition, Offline Prerequisite Installation

September 2025 SharePoint 2016 CU - Configuration Wizard failed