Easily determine your sites Content Database with a Custom Application Page
Posted: March 19, 2009 Filed under: Application Pages, ContentDatabases, Development, SharePoint 3 Comments »During last nights presentation at the Houston’s SharePoint Users Group I demonstrated how to create a simple application page to determine the Content Database of any SharePoint site. While I have posted a link to the presentation in my previous post, I think the Application Page may be very useful to many and have decided to post it here to make it easier to find.
The application page looks as follows and is easily accessible on any site by appending “/_layouts/ShowContentDatabase.aspx” to the URL of the SharePoint site:
Creating the Application Page is very simple.
- Go to your LAYOUTS folder, usually located in “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS”
- Create a new file named “ShowContentDatabase.aspx”
- Add the following code the your file and save your changes.
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%> <%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" %> <%@ Import Namespace="Microsoft.SharePoint" %> <script runat="server"> protected override void OnLoad(EventArgs e){ SPSecurity.RunWithElevatedPrivileges(delegate() { lblContentDatabase.Text = SPContext.Current.Site.ContentDatabase.Name; }); } <asp:content id="PageTitle" runat="server" contentplaceholderid="PlaceHolderPageTitle"> Content Database <asp:content id="PageTitleInTitleArea" runat="server" contentplaceholderid="PlaceHolderPageTitleInTitleArea"> Content Database <asp:content id="Main" runat="server" contentplaceholderid="PlaceHolderMain"> Content Database: <asp:Label ID="lblContentDatabase" runat="server" />
That’s it. The page should be saved to the LAYOUTS folder in each of your Web Front End (WFE) servers.. I would recommend packaging the page in a WSP file and deploying it that way if you have the time.

Is this only working for 2007?
I can't get it to work om 2003..
I get: Could not load type System.Web.UI.WebControls.content from assembly System.Web, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Sorry Maarten, I've never tried it on 2003. I dont believe it will work.
Ok, thanks anyway for responding to my question