The Current Number of Site Collections is 0 in SharePoint After Database Attachment

Problem:
During a production SharePoint site cloning into UAT using Database attachment method, after attaching the content database to the web application in UAT environment, found the current number of site collections is 0 (zero). All site collections are missing! I tried “View All Site Collections”  from the SharePoint 2013 Central Administration site and found nothing! No site collections are listed.

sharepoint 2013 current number of site collections 0

Troubleshooting:

  1. As the first step in troubleshooting, installed patches to the UAT environment to bring it on the same patch level.
  2. Tried upgrading the database: Upgrade-SPContentDatabase <database_name>
  3. Tried refreshing the site map in the config db:
    1
    $Database = Get-SPContentDatabase -Identity "Database_Name" $Database.RefreshSitesInConfigurationDatabase()
  4. None of the above helped! Finally, tried running Test-SPContentDatabase and found the answer!
    1
    Test-SpContentDatabase -name "WSS_Content_KM_New" -webapplication https://intranet.crescent.com -ServerInstance "Abj-SQL-001" > Result.txt
    and the output of the above was the answer:
    current number of site collections 0 sharepoint

Root cause:

Site Collection GUIDs are unique to the SharePoint farm. So, If a content database is restored even to a different Web Application on the same farm – Site collections will not appear if the farm has a duplicate GUID of the site collection. In my case, this issue was raised because of the error content database in a previous attempt!

Solutions:

  • Delete the existing site collections which are causing the conflicting GUIDs issue from the LOG file above.
  • Detach the existing content database which is triggering the duplicate issue.
  • Take the backup of the site collection and  restore it a different web application using again PowerShell/STSADM. How to Copy site collection in SharePoint

Also, make sure you specify the right SQL server while mounting the database in case of multiple database servers in your environment. E.g.,

Mount-SPContentDatabase "WSS_Content_KM" -DatabaseServer "Cre-SQL01" -WebApplication https://portal.crescent.com

Otherwise, SharePoint creates a new database on the default database server instance (obviously, the site count would be ‘0’ on a new content database, isn’t it?)

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

One thought on “The Current Number of Site Collections is 0 in SharePoint After Database Attachment

  • Hi

    Thanks you. I spend half a day looking for answer. the DBA gave up trying backup / restore for me. finally. you’re are AWSOME!!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *