Detach And Attach Content Database From One SP Farm To Another SP Farm

This article will help you to understand how to detach and attach the content database from one SharePoint Farm to another.

In the world of technology, we often need to migrate the user data from one place to another place in order to keep the application up-to-date. For the same reason, in SharePoint, we often migrate our content database from one farm to another farm or one version to another version.

So here, I will explain the easy method to move your content database from one environment to another environment. I will move the content database called “EDEMO” from http://dev.sharepoint.com environment to http://prod.sharepoint.com.

Note
Before proceeding, make sure that you have taken the SQL backup and stored it in a different location and made sure that both SharePoint Farms are using the same database version.

In my case, I have taken the SQL backup and stored it in a different drive and as my first step, I made that database status offline by clicking Application Management -> Manage Content Database -> click that database and change the status to offline.

Detach And Attach Content Database From One SPFarm To Another SPFarm
Step 2
 
Go to SQL Server and open Management Studio. Then, select that database, right-click, and choose Tasks >> Detach.
 
Detach And Attach Content Database From One SPFarm To Another SPFarm

On the next pop-up, tick "Drop Connections" and "Update Statistics" options to detach the database smoothly.

Detach And Attach Content Database From One SPFarm To Another SPFarm

Or, you can run the below-mentioned PowerShell script to detach the content database.

  1. Dismount-SPContentDatabase –WebApplication http://sharepoint.com –Name “DatabseName”  

Note
Don’t execute Remove-SPContentDatabase cmdlets, it will remove the content database permanently.

Step 3

Go to your database storage location to grab the .mdb file and log file to move to the destination location. In my case, I installed SQL to c:\\programfiles\MSSQL\instanceName\Data.
 
Detach And Attach Content Database From One SPFarm To Another SPFarm

Step 4

Once you've moved the database to the destination location, open Management Studio on the destination server and right-click the database folder. Select the "Attach" option.
 
Detach And Attach Content Database From One SPFarm To Another SPFarm
 
Step 5
 
On the next pop-up, click ADD, as highlighted below.
 
Detach And Attach Content Database From One SPFarm To Another SPFarm
 
Step 6
 
Browse your .mdb file and click OK.
 
Detach And Attach Content Database From One SPFarm To Another SPFarm

Step 7

Once you have selected the .mdb file, it will automatically include the log file also and click OK after verifying the options.
 
Detach And Attach Content Database From One SPFarm To Another SPFarm
 
Step 8
 
Now, it will take a few minutes to attach the content database.
 
Detach And Attach Content Database From One SPFarm To Another SPFarm
 
Step 9
 
Navigate to the "Manage content database" page and you can use the "Add Content database" option there to attach the database to your web application
Detach And Attach Content Database From One SPFarm To Another SPFarm
Step 10
 
You can run the below mentioned PowerShell command to attach the content database to the respective web application.
  1. Mount-SPContentDatabse –WebApplication http://sharepoint.com –Name “DatabaseName”  

Step 11

Once the command executed successfully, then navigate to the manage content database and see whether content database is attached correctly or not.
 
Detach And Attach Content Database From One SPFarm To Another SPFarm

Another method to verify if the content database is successfully attached to the respective web application is by navigating Central Administration -> Application Management -> View all Site Collections.

Detach And Attach Content Database From One SPFarm To Another SPFarm

Here, you can see all the site collection information which was available in the content database.