I accidentally removed one of the content databases from a web application. I mounted it back but now the content database shows zero site collections in it.

I really messed up the production system, can anyone help me?



You probably need to update the site map in the config db:

$db = get-spcontentdatabase -Identity [insert guid of cdb here]
  • 1
    I really don't understand what's going on here. CDB shows 1 site in it now, but the site comes up all empty even though I see all the data in AllUserData tables. – Élodie Petit Feb 20 '12 at 13:09
  • 1
    All the data is there but I can't see them. Really annoying. – Élodie Petit Feb 20 '12 at 13:21
  • May be you need to run the configuration wizard to get things back in the right way? Or is it that you have changed an IIS setting too? Can you also check whether basic authentication is enabled in your IIS web site? – Deepu Nair Feb 21 '12 at 6:14

This might certainly be it. It might also be trying to create one on the default SQL server and not the one you want. We have 3 sql servers in our farm and it was going to the 1 instead of 2.

This is an old point but I did want to point out something. When you run the command:

Mount-spcontentdatabase -name (name of your db) -webapplication (name of your web app)

If you happen to spell the database name wrong it will create a new database in SQL and it will then show you 0 sites. I've seen it happen and I've done it before.

Just thought I might pass that tip on.


I know this question is nearly a year old, but we recently had a similar problem and I thought I'd post here in case it helps anyone else. We had the same issue, a web application that, according to central admin, had a single content database with 0 site collections in it.

I ran the following commands:

$app = get-spwebapplication –identity “url of the problem web app”

Which outputted 2 instead of the 1 I was expecting (and that central admin was showing).

These findings led me here.

So I ran the suggested SQL query on the config database looking for the dodgy database reference in the Xml.

When I had this guid I ran the suggested commands:

$db = get-spwebapplication –identity “url of the webapplication that had the null entry” 

However, this gave a null reference exception.

I then ran these commands:

$db = Get-SPDatabase -Identity "guidOfProblemDb"

Finally I ran the commands that Wictor suggested

And central admin finally accepted that there was a site collection in the content database and over the course of an hour or so the web application started working properly again (I'm guessing that this was caused by numerous time jobs).


Did you check to make sure that you mounted the right db. If you type the database name wrong it will create a new database and it will show 0 current site count. I know - I've done this and because I didn't refresh the sql node I didn't see the new content_database listed.

For example: Your content database is named:


You meant to type

mount_spcontentdatabase -name wss_content_help0101 -webapplication http:// server

But instead you type:

mount-spcontentdatabase -name wss_content_help101 -webapplication http:// server

You will see that the database is attached to the web app but it will show 0 for the currentsitcount. Now if your upset that your site isn't up in the first place its easy to type the wrong name in powershell. What is annoying to me is that a new database is created and attached to the web application. I wish it would just throw back an error and state that the database doesn't exist but it doesn't. It just goes along its happy way and creates a new empty db for your web app.

This may not be what happened to you but this happened to me and its an easy mistake to make and can set you off on a wild goose chase.


Ok, I assume that you have removed the Content Database from the Web application but that is still existing in the SQL Server.

You can attach the Content Database using stsadm and perform the IISReset afterwards:

stsadm -o addcontentdb -url http://server:port/ -databasename WSS_Content_New -assignnewdatabaseid  -databaseserver  yourdatabaseserver 

Run a IISReset /noforce

  • This didn't solve the problem. The database is attached successfully but the data is not there again. – Élodie Petit Feb 20 '12 at 17:26

It's possible the reason is because the version numbers for your FARM 1 SQL DB is different from the one on FARM 2.

Try upgrad both servers to the same built number.

  • You realise I asked this question 4 years ago, right? :-) Thanks anyway. – Élodie Petit Nov 28 '15 at 5:23
  • 1
    I faced the same problem, in research just finding your inquiry. :) – Diego Hillesheim Nov 30 '15 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.