Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

Thanks.

share|improve this question
    
Did you mount using PowerShell or just a "SQL restore" –  Wictor Wilen MCA MCM MVP Feb 20 '12 at 12:40
    
I tried both ways. –  Élodie Petit Feb 20 '12 at 12:42
    
I am not familiar with content database structure but just to be sure I checked the Sites table in the db and I can see the site collection record in there. –  Élodie Petit Feb 20 '12 at 12:47
add comment

5 Answers

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

$db = get-spcontentdatabase -Identity [insert guid of cdb here]
$db.RefreshSitesInConfigurationDatabase()
share|improve this answer
    
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
    
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
add comment

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

share|improve this answer
    
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
add comment

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:

wss_content_help0101

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.

share|improve this answer
add comment

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).

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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