Thursday, July 12, 2012

Fetch Database Name From Database Id In SharePoint Farm

Fetch Database Name From Database Id In SharePoint Farm

When working with SharePoint Databases oftentimes the only way SharePoint identifies the database is via a GUID. Sometimes this can be frustrating because you want to know exactly what database you are working with. As far as i know there is no STSADM command available to easily translate GUID to Database name.

Word of warning, the following script directly queries a SharePoint database; this is never a good idea. Therefore I recommend you restore the database to a restore or test server where you can execute the query as to prevent any potential issues with your production environment.

Luckily there is a way to get this information from SQL Server, to do this you must run a query against the Configuration database (See warning above).

First you need to open Management Studio
 1. Select New Query.
 2. Select the Configuration Database from the Available Databases dropdown list.
 3. Copy the script below and paste it into the Query window and press Execute.

Select ID, Name from objects
 where properties like
 '%Microsoft.SharePoint.Administration.SPContentDatabase%m_nWarningSiteCount%'

This will output the Database GUID and Database Name in a nice list, giving you the data you need to identify what database SharePoint is talking about when it is talking GUID’s to you.

As stated There is some risk involved in running queries against SharePoint databases, Microsoft advises not to run any query against a SharePoint database as it might interfere with any SharePoint processes running against the databases. When this happens the database will lose support status and if you need to contact Microsoft for support with issues in the future you might be asked to replace the database with a fresh copy. I usually restore a recent backup of the configuration database to a restore server or a test server and run the query there. This allows me to get the data but still comply with the “No query for you!” rule that SharePoint databases have.