This documentation is archived and is not being maintained.

SPContentDatabaseCollection Class

Windows SharePoint Services 3

A collection of references to content databases that are used by a single Web application.


Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public class SPContentDatabaseCollection : SPBaseCollection

Use the ContentDatabase() property of the SPSite class or of the SPWorkItemCollection class to return the content database for a site collection or work item collection. Use the ContentDatabases property of the SPWebApplication class to return the collection of content databases that are used by the Web application.

To add a content database, use the Add() method.

Use an indexer to return a single content database from the collection. For example, if the collection is assigned to a variable named myContentDatabases, use myContentDatabases[index] in C#, or myContentDatabases(index) in Visual Basic .NET, where index is either the index number of the database in the collection or the GUID for the content database.

The following code example displays information about the content databases of all the SharePoint Web applications within a Windows SharePoint Services server farm.

SPServiceCollection services = SPFarm.Local.Services;

foreach (SPService service in services)

    if (service is SPWebService)
        SPWebService webService = (SPWebService)service;
        SPWebApplicationCollection webApplications = webService.WebApplications;

        foreach (SPWebApplication webApplication in webApplications)
            SPContentDatabaseCollection contentDBs = webApplication.ContentDatabases;

            foreach (SPContentDatabase contentDB in contentDBs)
                Response.Write(webApplication.DisplayName + " :: " 
                    + contentDB.CurrentSiteCount.ToString() + " :: " 
                    + contentDB.MaximumSiteCount.ToString() + " :: " 
                    + contentDB.Name + "<BR>");

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread safe.