共用方式為


SPContentDatabaseCollection Class

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

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.SPBaseCollection
      Microsoft.SharePoint.Administration.SPContentDatabaseCollection

Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
<GuidAttribute("4FFCB8E5-7B15-4b81-AC4E-99A2181AD33E")> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public Class SPContentDatabaseCollection _
    Inherits SPBaseCollection
'Usage
Dim instance As SPContentDatabaseCollection
[GuidAttribute("4FFCB8E5-7B15-4b81-AC4E-99A2181AD33E")]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public class SPContentDatabaseCollection : SPBaseCollection

Remarks

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.

Examples

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

Dim services As SPServiceCollection = SPFarm.Local.Services

Dim service As SPService
For Each service In  services

    If TypeOf service Is SPWebService Then

        Dim webService As SPWebService = CType(service, SPWebService)
        Dim webApplications As SPWebApplicationCollection = webService.WebApplications
        Dim webApplication As SPWebApplication

        For Each webApplication In  webApplications
            Dim contentDBs As SPContentDatabaseCollection = webApplication.ContentDatabases
            Dim contentDB As SPContentDatabase

            For Each contentDB In  contentDBs
                Response.Write((webApplication.DisplayName + " :: " 
                    + contentDB.CurrentSiteCount.ToString() + " :: " 
                    + contentDB.MaximumSiteCount.ToString() + " :: " 
                    + contentDB.Name + "<BR>"))
            Next contentDB 
        Next webApplication
    End If 
Next service
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>");
            }
        }
    }
}

Thread Safety

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.

See Also

Reference

SPContentDatabaseCollection Members

Microsoft.SharePoint.Administration Namespace