Cannot Delete SharePoint Web App (Orphaned DB)

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 using Remove-SPWebApplication due to this error:

An object in the SharePoint administrative framework, SPWebApplication Name=webAppName, 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: 

Screenshot: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

Diagnosis

There could be multiple possible causes for this symptom, but one way to reproduce the error is attempting to delete the web application and its content database without the sufficient permission on the SharePoint configuration database. In that scenario, the physical content database is dropped in SQL Server, but removing its reference from the config DB fails -- leaving behind the orphaned entry:

Failed to delete web application due to database permission

When attempting to delete the web application again after the database permission failure, it triggers the same error as seen in PowerShell above.

Same Error on Central Admin: 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:

Once in this state, standard troubleshooting steps proved ineffective. Without knowing what happened behind the scenes, I tried locating the associated Timer job, restarting the SPTimerV4 and SPAdminV4 services, running iisreset across all farm servers, and even rebooting all the servers. I had no idea which "other objects depended on it", and standard administrative views showed no obvious clues, yet the web application still refused to delete.

The problem lies with the orphaned or corrupted content database object in the config DB 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" (ignore the SpFarmAdmin database; it's for the content DB of Central Admin):

Corrupted Content Database Found with Get-SPDatabase

Another way to check the orphaned status is by running Get-SPSite. 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

Remedy

The solution is to delete the orphaned database reference in the config database. It can be done by calling the Delete() method on the orphaned DB after obtaining it with its ID (screenshot above).  

Warning: Always ensure of the database backup and double-check the database GUID before proceeding. This is a permanent action.

Once the orphaned database is removed, the Remove-SPWebApplication command runs successfully:





Comments

Popular posts from this blog

SharePoint Subscription Edition, Offline Prerequisite Installation

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

Strange Read-Only Behaviors of Site Collections