What To Do When “Current Number Of Site Collections” Is Showing Incorrectly In Manage Content Databases If Creation Of Sites Using Powershell Script Failed

Let’s say you have a SharePoint Web application with two sites in a content database.


Now, you are creating 30 additional SharePoint sites using PowerShell script in the same web application and it shows the below error.

PS E:\temp> .\sitesCreation.ps1
New-SPSite : Cannot open database "TEST_SPContent1" requested by the login. The login failed.
Login failed for user 'Domain\userID'.

This error basically means that you do not have enough permission to create a site in the content database. So, you need to give sufficient permission (DB owner) to your account in the Content Database and run the script again.

But in-between, if you go to see the "Manage Content Databases" in Central Admin site, sometimes you will see the Current Number of Site Collections is showing 2+30 = 32 sites, when it should be two because your site creation was not successful.

To show the correct number in Current Number of Site Collections column, you need to detach and attach the content database. Then, it will show the correct number.

Before that, please note down the details of Database Server and Database Name.

To detach the content database, open the content database, check Remove Content Database, and click OK.


To attach the same content database, click "Add content database" and fill the noted Database Server and Database Name. Finally, click OK.

Then, you can see the correct number of current site collections.


Once this is rectified, you can run the script to create the sites.

Hope it helps!