PortiBlog

Cannot create new site collections – Content database already exist

18 september 2014

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

pic1-getwebapp

2. Run this SQL query against configuration database.

select ID, Name, CAST (properties as xml) from Objects where ID = 'b92c5915-99ca-4ffa-b095-17f778b2036c'

pic2-getnull

And find in the de xml which database has a fld of null.

  1. The results returned from step 2 will have 1 column with the properties as xml. Click on the results and it should open a new window in SQL Mgmt studio with xml output.
  2. Carefully read through the tag that stores the above searched word. You should be able to see fld tags. Find out a tag which has fld tag with value null. This is the orphan database. Its GUID is the xml line above where you found null.
  3. Cross verify all databases currently associated with the web application and make sure this database is not getting used. And check also again in SharePoint PowerShell if it is not listed!

Get-SPWebApplication | %{Write-Output "`n- $($_.url)"; foreach($cd in $_.contentdatabases){Write-Output $cd.name $cd.id "" }}

  1. Run below powershell script,

$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.

  1. Run a SQL query on the config database on table: dbo.SiteMap to get the ID of the old database
  2. To get rid of this ID in the config database we have to remove it by SharePoint PowerShell:
  3. $db = Get-SPDatabase -Identity " ID-of-old-bad-content-db " $db.Delete()
  4. To be sure dismount the database you want to add.
  5. Dismount-SPContentDatabase "YOUR-DB-NAME"
  6. Then you can mound you’re database with the powershell command:Name                            : YOUR-DB-NAMEServer                           : DBSERVER
  7. CurrentSiteCount            : 1
  8. WebApplication              : SPWebApplication Name=SharePoint- YOURRWEBAPPLICATION
  9. Mount-SPContentDatabase " YOUR-DB-NAME " -DatabaseServer "YOUR-DB-SERVER" -WebApplication http://YOURRWEBAPPLICATION This wil give us the result that the database and the site-collection are available. Id                                 : 691cb3b3-4397-4c07-b747-8a9fd93f6f90
  10. Now the database is added again.

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

Submit a comment