Friday, 23 December 2016

Object reference not set to an instance of an object While Creating Site collection

Hi All,

Once I was creating a Site collection and got a strange error message that is "Object reference not set to an instance of an object". While every this was working in our environment but I was continuously getting this error on our Preprod environment. When I did further research and Check ULS Logs, I found following error,
Failed to provision site [project web access instance name] with 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)

This error can be occur while creating site collection, site, Site backup or restore, or an particular site.

To solve these errors we performed the following steps:
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 = ‘Webapplication ID’

And find in the 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.      Search for the word "m_Databases" in the xml output.
  1. 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.
  2. 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 $ $ “” }}
3.      Run below powershell script,
$webapp=get-spwebapplication ""

This script will give some error message but the null entry will be gone. And you will be able to perform your task.

No comments:

Post a Comment