To create a new web application which will use an existing content database we need to do the following.
Open Sql Server Management Studio
To take back up of the database in my case it was ‘WSS_Content_fa5cc7a0686e424bbe4fc128b4a48cf4’
Right click the database — select tasks —select Offline—then select Detach.
Get the mdf and ldf file for the database.
Attach the files and create a new database.
Now to Central Administration Site — Application Management — Create a new web application
Let the name of the database as default.
Now go to Content Database within Application Management — Select the web application just created.
Click on the Database Name — Select Database Status as Offline and Check Remove Content database check box.
Now click on Add Content Database— In the Database Name specify the name of the new restored database.
This is the point we can get this error “A SharePoint database named ‘….. ‘already exists. You must supply another name for the new database”
The solution for this is to go to
SharePoint_Config database —There run this query
delete from Objects where name=’name of restored db’;
Bye
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.

N,
when i run the query i get :
Msg 547, Level 16, State 0, Line 1
The DELETE statement conflicted with the REFERENCE constraint “FK_Dependencies1_Objects”. The conflict occurred in database “SharePoint_Config”, table “dbo.Dependencies”, column ‘ObjectId’.
The statement has been terminated.
Any ideas.
Mike
LikeLike
hi mike got any solution for that
LikeLike
Thank you!!
hairpoint.. mean sharepoint bugging me with this for hours!
LikeLike
Well do you think changing the sharepoint database is recommended. I spoke to people at MS and they say any changes to database is not supported by MS.
LikeLike
Hi Kaajal, making changes to the databases are not supported i.e to either it’s structure or values inside it. However if you are just taking backup and restoring the databases it’s absolutely fine !!
LikeLike
But then you said we can modify ( delete from objects) the database and remove the orphan entry
LikeLike
I am facing the same problem.
Can anyone guide me.
I am unable to create a new webapplication
as it says a sharepoint database say x already exists.
I guess some reference has been on that.
How to remove that any idea.
Thanks
Shafi
LikeLike
This is not a solution…did you actually test this and try it out before posting?
LikeLike
I received this error after my SQL disk filled up.
I unconsumed the Site Content DB and couldn’t reconsume it.
In order to clear the error and re-consume the site content db, I had to:
1. free up space on sql
2. delete the reference from the sharepoint_config db (don’t ever do this :p)
use sharepoint_config
go
delete from Objects
where name = ‘your_site_content_db_name_here’
3. reconsume the site content db
LikeLike
Thanks! I got stuck because my content database was still listed in Objects, but it didn’t exist anymore. Something had gone awry when I removed the content database using CA. Guessing some process hadn’t completed before I dropped the database in SQL Server. Nothing I tried cleaned it up enough to attach a backup of the database. Couldn’t even delete the web application to start over! I used the “delete from [objects] where name='[mycontactDB]'” and was then able to reattach the content database. Hate that I had to touch a SP database, but was left with little alternative (oh, sure, I could have rebuilt the entire farm–YUCK!). Fortunately, this wasn’t a production environment.
LikeLike
Yes, this is NOT a supported method.
Check your destination farm in Central Admin under the section Manage Content Databases. If a Content Database of the same name exists you will need to remove it before running the Mount command again.
You can remove the database by clicking on the content database, check the delete content database checkbox and click ok.
I hope this helps.
LikeLike
I had the same issue Mike had. My situation was that I restored a SP2007 DB to a SP2010 WEBAPP. I got an error when trying to delete the content database via the CA (object not set to a reference or something like that) Used the stsadm deletecontentdb command to remove the DB from the webapp.
LikeLike
Hello!
I have the same problem. Solution:
1- Open a SharePoint PowerShell console.
2- Execute: Get-SpDatabase and look the database GUID.
3- Execute: $database = Get-SpDatabase -Identity “GUID”
4- Execute: $database.Delete()
5- Attach your database….. Problem solved!
I hope it´s help you
LikeLike
Thanks Javi,
you saved my live and farm… 🙂
for me working perfect!!!
Get-SpDatabase
$database = Get-SpDatabase -Identity “My DB GUID”
$database.Delete()
DONE!!!
LikeLike
Javi, that’s Fantastico!
LikeLike
I feel this is the “Right way” to do this. Your choice!
You can test it by just changing the database in in the variable and when you are ready to run it, un-remark the last two lines.
Jut FYI, this just removed the reference from SharePoint, you will have to delete it yourself, or you can use Remove-SPContentDatabase if you want it to delete it form SQL also.
$ContentDB = “DatabaseName”
Get-SpDatabase | Where-Object {$_.Name -eq $ContentDB } | Sort-Object name | ft name, type -AutoSize
#$database = Get-SpDatabase | Where-Object {$_.Name -eq $ContentDB }
#$database | Dismount-SPContentDatabase -Confirm:$false
LikeLike
Get-SPContentDatabase -WebApplication “WebApplication URL here”
Get-SPContentDatabase d04a6e13-c5e8-4355-9744-d8929ec27770 | Remove-SPContentDatabase
# where the Guid in previous line is the ContentDatabase guid that you want to remove as it us orphaned.
LikeLike