We recently had a problem that we were not able to attach a new content database in SharePoint 2013. Further troubleshooting this problem we realized that no new site collections could be created on the environment under the specific problematic web application only. Below is the error from ULS and user interface:
Error: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.SharePoint.Administration.SPContentDatabaseCollection.FindBestContentDatabaseForSiteCreation(IEnumerable`1 contentDatabases, Guid siteIdToAvoid, Guid webIdToAvoid, SPContentDatabase database, SPContentDatabase databaseTheSiteWillBeDeletedFrom) at Microsoft.SharePoint.Administration.SPContentDatabaseCollection.FindBestContentDatabaseForSiteCreation(SPSiteCreationParameters siteCreationParameAnd error:Cannot attach content database because it already exists |
To solve these errors we performed the following steps:
Problem 1: Cannot create new site collections
1. Run below powershell command to get GUID of web application.
get-spwebapplication | ? {$_.displayname -eq " You’re Web Application Name"} | fl
2. Run this SQL query against configuration database.
select ID, Name, CAST (properties as xml) from Objects where ID = 'b92c5915-99ca-4ffa-b095-17f778b2036c'
And find in the de xml which database has a fld of null.
Get-SPWebApplication | %{Write-Output "`n- $($_.url)"; foreach($cd in $_.contentdatabases){Write-Output $cd.name $cd.id "" }}
$webapp.contentdatabases.delete(‘ID-of-bad-content-db’)
Create a new site collection now and it should work again and the you saved the day.
Problem 2: Content database already exist
We attached a database and SharePoint tell us that the database already exist. But the database isn’t in SharePoint. In the past there was a database with the same name. To solve this error we performed the following steps.
In summary,
Follow this blog and it will work. For questions just contact us. We also created a ticket by Microsoft Support how this coot happen. Because it shoot not be happen. The result I will post in this blog.
Johan Biere & Alexander Meijers