Showing posts with label ContentDB Attach/Detach. Show all posts
Showing posts with label ContentDB Attach/Detach. Show all posts

Friday, December 13, 2013

SharePoint 2013 Site Collection | HTTP 404 error intermittently

Problem Description

Recently I came across a weird issue, a site collection in the SharePoint farm was giving HTTP 404 intermittently. My initial thought was maybe the whole web application had the issue but didn’t see this happening with any other site collections on the same web application. And I got this error only 1 out of 10 times. But another user seemed to have got it from the first try itself. It really baffled me for couple of hours. So I did an IIS reset and even restarted the SharePoint timer service on the SharePoint web front ends. That didn’t seem to help either.


Resolution

At some point, I realized that this was a site collection specific issue. This site collection had its own dedicated database. I had to detach and attach the content database of this site collection from the web application using Powershell (read dismount and mount)to resolve this issue.

Few weeks back I had done a detach/attach of the same content database from Central Administration. I think performing dismount and mount from Central Administration console led to this behavior. I still find this weird though.

P.S.: Please make a note of the Content DB name before you start this operation

Dismount-SPContentDatabase "<ContentDBName>"

Mount-SPContentDatabase "< ContentDBName >" -DatabaseServer "<DBServerNAme>" -WebApplication http://SiteName



Tuesday, October 15, 2013

Error while restoring a site collection in the same content database

I wanted 2 sites to be the exact same. So I was performing a backup of a site collection http://sharepoint.fahad.com/sites/siteA and was trying to restore it as http://sharepoint.fahad.com/sites/siteB .


Backup-SPSite -Identity "http://sharepoint.fahad.com/sites/siteA" -Path "C:\ Backups\siteA.bak” -force -verbose

Restore-SPSite -Identity "http://sharepoint.fahad.com/sites/siteB" –Path "C:\ Backups\siteA.bak" -force -verbose

The restore operation failed and gave me the below error:

Restore-SPSite: The operation that you are attempting to perform cannot be completed successfully.  No content databases in the web application were available to store your site collection.  The existing content databases may have reached the maximum number of site collections, or be set to read-only, or be offline, or may already contain a copy of this site collection.  Create another content database for the Web application and then try the operation again.

Reason

Both these site collections were in the same web application and it had only one content database. Microsoft uses the source site collection GUIDs during the installation. Though you delete the site collection from the web application, it leaves the GUIDs behind, and if you try to restore same site collection (same GUID) into same web application and content database, it would throw an error.

To resolve the issue, new content database needs to be created in the web application to restore the site collection.

Resolution

1.Create a new content database WSS_Content_siteB from Central Administration for your web application where your site collection is going to reside. Reference


2.Restore-SPSite -Identity "http://sharepoint.fahad.com/sites/siteB" -Path "C:\ Backups\siteA.bak" -force -verbose -ContentDatabase WSS_Content_siteB

Thursday, May 16, 2013

How to create a new Site Collection in a new Content Database from Central Administration


Please note that I am performing the below exercise on SharePoint 2013.

I am breaking this activity into two:

a) Creating a new content database
b) Creating a new site collection in the newly created content database

Creating a new content database

1) Browse to Central Administration -> Application Management -> Databases -> Manage Content Databases (Page Name - CNTDBADM.aspx)


2) Choose the web application (where you are going to create the site collection) from the drop down. Make sure all existing databases show the status as Stopped. If not click on the database that is in Started state and change the Database status to Offline. Click OK



3) Back to Content Databases page (CNTDBADM.aspx). Click on Add a content database
4) Enter the details: Database Server, Database Name .Click OK




5) The new content database would be listed in your Content Database page and status would be Started

Creating a new site collection in the newly created content database

1) Browse to Central Administration ->Application Management ->Site Collections ->Create site collections.
2) Choose the web application (where you are going to create the site collection) from the drop down.
3) Enter the details : Title ,Description ,URL ,Select Experience Version ,Select a template ,Primary and Secondary site Collection Administrator ,Quota Template(if any).click OK.
4) Site collection would be created in the new content database.

Wednesday, November 28, 2012

Moving SQL Database to a different drive

This situation usually arises when we might have to move SQL DB files to other drives at times due to space crunch. We can follow this activity to move these types of databases.
  • Configuration database
  • Central Administration content database
  • Content databases
  • Service application databases
This activity was carried out in MOSS 2007 with SQL 2005
P.S.
i) Make sure that a backup of the database is already taken before you start with this activity.
ii) Also check the DB owners remain the same before and after this activity.
iii) You might have to do a full crawl after completion of activity if results are not showing up in search

1) Quiesce the Farm
This is done to ensure that no new user sessions are initiated. Browse to Central Administration -> Operations -> Global Configuration -> Quiesce farm. Click "Start Quiescing".

2) Stop the below SharePoint Services
Type services.msc in Run.
1. Office SharePoint Server Search (alternatively net stop OSearch from command prompt)
2. Windows SharePoint Services Search (alternatively net stop SPSearch from command prompt)
3. Windows SharePoint Services Timer (alternatively net stop SPTimerV3 from command prompt)
4. Windows SharePoint Services Administration service (alternatively net stop SPAdmin from command prompt)
 5. Windows SharePoint Services Tracing service (alternatively net stop SPTrace from command prompt)

6. Windows SharePoint Services VSS Writer service (alternatively net stop SPWriter from command prompt)
 
3) Detach Database
Login to SQL Server. Run the below query:
use master
go
exec sp_detach_db @dbname = N ‘DBName', @keepfulltextindexfile='true';
go
Where DBName = content db /search ssp db you want to move

4) Move files to target location
Move the data and log files from the current drive location (F:\) to the target drive location (D:\).
Include the .mdf files and .ldf files

5) Attach Database
Login to SQL Server. Run the below query:
use master
go
exec sp_attach_db @dbName = N'DBName',
@filename1 = N'LocalPathToFile\DBName.mdf',
 @filename2 =N 'LocalPathToFile\DBName.ldf'
go
Where DBName = content db /search ssp db you moved
                    LocalPathToFile = file location

6) Start the below SharePoint Services
Type services.msc in Run
1. Office SharePoint Server Search (alternatively net start OSearch from command prompt)
2. Windows SharePoint Services Search (alternatively net start SPSearch from command prompt)
3. Windows SharePoint Services Timer (alternatively net start SPTimerV3 from command prompt)
4. Windows SharePoint Services Administration service (alternatively net start SPAdmin from command prompt) 
5. Windows SharePoint Services Tracing service (alternatively net start SPTrace from command prompt)

6. Windows SharePoint Services VSS Writer service (alternatively net start SPWriter from command prompt)

7) UnQuiesce the farm
Browse to Central Administration -> Operations -> Global Configuration -> Quiesce farm. Click "Reset Farm".
8) Try testing your application now.(access the sites, test search and ensure search settings are intact)

Monday, November 5, 2012

7 Sharepoint ContentDatabase FAQ's


1. Can we create a site collection in a specific Content Database?

Yes, but you can only do this by using PowerShell using the New-SPSite cmdlet. You can use the                         -ContentDatabase parameter to specify in which Content Database the site collection will be created. 
Make sure that the content database is already created. Else you will get an error saying the content database could not be found.
An alternative would be through Central Administration. But, that is a workaround.

2. If a site collection is outgrowing its content database size; can I add a second Content Database to it?

A SharePoint site collection cannot have more than one content database. If you want to split up your site collection in to multiple site collections, you can do this by exporting and importing subsites, or by using 3rd party tools.

3. How can I get a list of site collections in a Content Database?

Use this powershell command:Get-SPContentDatabase  Name of your Content DB
Get-SPContentDatabase | %{Write-Output "- $($_.Name)”; foreach($site in $_.sites){write-Output $site.url}}

4. Checking the size of my Content Database?

The easiest way to accomplish this is by looking at the database file on your SQL Server.

5. Which all Content Databases are attached to my Web Applications?

Below powershell command will return all Web Applications with their respective Content Databases:               Get-SPWebApplication | %{Write-Output "`n- $($_.url)"; foreach($cd in $_.contentdatabases){Write-Output $cd.name}}

6. How do I move my site collection to another Content Database?

In this case, there are 2 scenarios:
- Move the site collection to another Content Database that is attached to the same Web Application
Move-SPSite cmdlet to move the site collection.
(eg. Move-SPSite sitecollectionURL –DestinationDatabase WSS_Content_DBName)

- Move the site collection to another Content Database that is attached to another Web Application
Backup-SPSite and Restore-SPSite powershell commands

7. Can we use the same Content Database for more than one Web Application?

No, this is not possible. A Content Database can only be attached to a single Web Application.



SPContentDatabase Powershell Commands


New-SPContentDatabase
Creates a new content database and attaches it to the specified Web application.

C:\PS>New-SPContentDatabase "MyDatabase" -DatabaseServer "MyServer" -WebApplication http://sitename
This example creates a new content database for the sitename Web application.

Remove-SPContentDatabase
Deletes a content database.

C:\PS>Get-SPContentDatabase 12345678-90ab-cdef-1234-567890abcdef | Remove-SPContentDatabase
This example deletes the specified content database.

Get-SPContentDatabase
Returns one or more content databases.

C:\PS>Get-SPContentDatabase -webapplication http://sitename
This example returns all content databases used by the sitename Web application.

C:\PS>Get-SPContentDatabase -site http://contoso.com
This example returns the content database that contains the site collection at http://contoso.com.

Set-SPContentDatabase
Sets global properties of a SharePoint content database.

C:\PS>Get-SPContentDatabase http://contoso.com | Set-SPContentDatabase -MaxSiteCount 1
This example sets the MaxSiteCount for the content database that contains contoso.com to 1.

C:\PS>Get-SPContentDatabase -WebApplication http://sitename | Set-SPContentDatabase -WarningSiteCount $null
This example clears the WarningSiteCount for all databases in the sitename Web application.

Mount-SPContentDatabase
Attaches an existing content database to the farm.

C:\PS>Mount-SPContentDatabase "MyDatabase" -DatabaseServer "MyServer" -WebApplication http://sitename
This example mounts an already existing database to the sitename Web application.

Dismount-SPContentDatabase
Detaches a content database from its currently associated Web application.

C:\PS>Dismount-SPContentDatabase 12345678-90ab-cdef-1234-567890abcdef
This example detaches the content database with the GUID 12345678-90ab-cdef-1234-567890abcdef from its current parent Web application.

C:\PS>Get-SPContentDatabase -WebApplication http://sitename | Dismount-SPContentDatabase -WhatIf
This example detaches all content databases from the Web application on port 80 of the local machine. Remove the WhatIf parameter to perform the operation.

Thursday, October 18, 2012

Content database exclusively for one site collection from Central Administration


There are times when we would want to create a content database exclusively for one site collection.
I learnt a work around from one of my seniors (Manish Chopra) long time back(between 2007-2008) while I was working for Honeywell


1)Browse to Central Administration -> Application Management -> Manage content databases



2) Add a new content database for your web application.



3)So now you have 2 content database for your web application.



4)Now change the database capacity settings for your web applications other content database .

P.S. The database capacity setting values must be greater than the number of existing sites in the database, and warning site count must be less than the maximum site count.



5) Create a new site collection.This would be created in the new content database [WSS_Content_1000_additional]




6)Now repeat step 4 for your new content database[WSS_Content_1000_additional].Revert back the settings to default for the old content database[WSS_Content_1000].

7) You are all set now.All new site collections would be created in your old content database[WSS_Content_1000].And the newly created content database [WSS_Content_1000_additional] would be exclusve for the site colelction you created in step 5.

Tuesday, October 16, 2012

How to create new site collection in new content DB in SharePoint


Option 1:

In this case from central administration, I am going to create a new content database and then change the Maximum Number of Sites value to equal Current Number of Sites for all the databases except the new one to make sure that the site is created in new database(temporarily).[I will post a different article for this soon and link it from here :- )][http://pitstopsharepoint.blogspot.com/2012/10/content-database-exclusively-for-one.html]

1. Create a new content database for the given web application (Central Administration -> Manage Content Databases)

2. Change the values for the Maximum Number of Sites value to equal Current Number of Sites (Central Administration -> Manage Content Databases)

3. Create the new site collection from the central admin (Central Administration -> Create Site Collection)

 
4. Revert back the changes (Central Administration -> Manage Content Databases)

Option 2:
In this case, we are creating a new content database first for the web application and then creating the site collection in that content database.

1. Add New Content Database to the Web Application

New-SPContentDatabase -Name <content_db_name> -WebApplication <web application URL>

2. Create New Site Collection in the New Content DB

New-SPSite <required site collection URL> -OwnerAlias <owner account name including domain name e.g.domain\username> -ContentDatabase <content_db_name> -Name <Name of your site collection> -Description <Description of site collection> -Template <template name,team sites template name is “STS#0″>

Thursday, October 11, 2012

How to create an additional content database for a sharepoint web application

Run the following commands from powershell
1) Get-SPWebapplication - This command gets you a list of web applications in the farm
2) Create an additional content database for one of these webapplications

New-SPContentDatabase DemoContentDB -DatabaseServer SP2010 -WebApplication http://sp2010:1000/
3) Let us check in SQL if the database is created.

4) The database is listed .
5) Now to confirm the database is attached to the correct webapplication, browse to Central Admin->Manage Conetnt Database->Select the desired application
The new database is attached to the web application





Tuesday, June 26, 2012

Attaching and Detaching a Sharepoint Content Database to a Webapplication

                A common scenario where we might have to attach and detach a database is when the webapplication is down due to some reason.And because of this you are not able to access any of the site collections in this particular web application.

Usually this happens when a lot of team members login to the development server with the service account(which is not recommended) and carry out different activities and somehow the webpplications gets corrupted and wont be accessible though it shows up in the Central Administration console.
In case you have already spent more than an hour to bring your webpplication up and still there are no results you can follow the below steps,

1) Delete the existing web application
2)Create a new web application at the same port
3)Add your old content database to the same webapplication

Detailed steps



1) Delete the existing web application

i) Browse to Central Administration -> Application Management -> Manage Content Databases.

ii) Select the webpplication you are planning to delete.Make a note of the associated database and copy it to a notepad.

iii) Browse to Central Administration -> Application Management -> Manage web Applications.

iv) Select the web application which is having the issue -> Delete.

v) A prompt box pops up.Make the selection as shown below.


vi) Now your webapplication and the associated IIS website is also deleted.But your contnet database is still intact in the SQL database.

2)Create a new web application at the same port

i) Browse to Central Administration -> Application Management ->New

ii) Create a new Web Application at the same port where you deleted your old web application.

3)Add your old content database to the same webapplication

i) Browse to Central Administration -> Application Management -> Manage Content Databases.

ii) Select the webpplication you just created -> Add a content database.



iii) The Add Content database page shows up.



iv) Copy and paste the database name which you had copied in step 1. Click OK.

v) Now you would see two content databases for your webapplication.Your old content database is now connected to new web application you created in step 2.




You should be able to access your old site collections now with the same URL.