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] $db.RefreshSitesInConfigurationDatabase()
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” $app.contentdatabases.count
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” $db.contentdatabses.delete(“guidOfProblemDb”)
However, this gave a null reference exception.
I then ran these commands:
$db = Get-SPDatabase -Identity "guidOfProblemDb" $db.Delete()
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
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.