Share via


Reporting Services WMI 提供者

Reporting Services WMI 提供者是以標準 Windows Management Instrumentation (WMI) 技術為基礎所建立的,可用來存取企業環境中的控制與管理資訊。Reporting Services 的 WMI 提供者可做為執行個體提供者,以便將報表伺服器 XML 組態元素對應至一組類別,這些類別包含了您可以呼叫以加入、移除或是修改報表伺服器組態資訊的方法。如需這些類別的詳細資訊,請參閱<Reporting Services WMI 提供者程式庫>。

WMI 提供者概觀

WMI 類別位於 Reporting Services 中,可允許自本機與遠端電腦控制報表伺服器與報表管理員元件、提供方法以探索在執行報表伺服器的 Web 服務之網路中有哪些電腦,以及將報表伺服器執行個體啟動成為向外延展部署。系統管理員與資料庫管理員可以使用這些類別,在安裝完成後對報表伺服器與報表管理員的組態進行變更,或是執行本機或遠端伺服器管理工作。工作包含了修改報表伺服器與報表伺服器資料庫之間的資料庫連接認證、修改報表伺服器資料庫的名稱,以及變更用以定義報表伺服器執行個體或是報表管理員之安裝路徑的 URL。

為了支援這些功能所安裝的類別如下所示:

在本主題顯示的程式碼範例使用 System.Management 命名空間來取得有關 Reporting Services 的資訊,您可以在 Microsoft.NET Framework 中找到其相關資訊。System.Management 命名空間提供一組 Managed 程式碼類別,.NET Framework 應用程式可以透過這些類別來存取和操作管理資訊。如需有關使用 System.Management 命名空間以運用 Reporting Services WMI 類別的詳細資訊,請參閱 Microsoft.NET Framework SDK 中的<使用 System.Managment 存取管理資訊>。

尋找報表伺服器執行個體

如果電腦已安裝報表伺服器的多個執行個體,管理員需要指向已修改屬性之電腦上的正確執行個體。若要直接尋找執行個體,每個類別都包含定義為索引鍵的屬性。這個索引鍵屬性會唯一識別報表伺服器安裝。定義為索引鍵的屬性是 PathName 屬性。此屬性值是 RSReportServer.config 組態檔的路徑,包括組態檔的名稱。對於大部分的安裝,此路徑類似於下列範例:

C:\Program Files\Microsoft SQL Server\MSRS10.<InstanceName>\Reporting Services\ReportServer\rsreportserver.config

在建立 MSReportServer_ConfigurationSetting 類別之後,您可以擴展索引鍵,並搜尋電腦是否有符合該索引鍵之報表伺服器或是報表管理員的執行個體。若有找到,請使用從該執行個體的其餘值來擴展管理集合。

您也可以擴展集合以取得資訊,並對管理類別執行迴圈以顯示資訊。如果您從 Visual Studio .NET 執行這個程式碼,請將專案參考加入系統管理。以下範例假設 RSReportServer.config 組態檔是位於 C:\Program Files\Microsoft SQL Server\MSRS10.<InstanceName>\Reporting Services\ReportServer\bin。在 System.Management 類別中的方法描述可在 Microsoft Visual Studio .NET SDK 中找到。

在報表伺服器安裝上尋找資訊的最好方法,就是列舉 WMI 執行個體集合。以下範例顯示如何建立集合,以及對集合執行迴圈以顯示屬性,來尋找每個報表伺服器執行個體上的屬性。

Imports System
Imports System.Management
Imports System.IO

Module Module1
    Sub Main()
        Const WmiNamespace As String = "\\<ServerName>\root\Microsoft\SqlServer\ReportServer\<InstanceName>\v10\Admin"
        Const WmiRSClass As String = _
           "\\<ServerName>\root\Microsoft\SqlServer\ReportServer\<InstanceName>\v10\admin:MSReportServer_ConfigurationSetting"

        Dim serverClass As ManagementClass
        Dim scope As ManagementScope
        scope = New ManagementScope(WmiNamespace)
        'Connect to the Reporting Services namespace.
        scope.Connect()

        'Create the server class.
        serverClass = New ManagementClass(WmiRSClass)
        'Connect to the management object.
        serverClass.Get()
        If serverClass Is Nothing Then Throw New Exception("No class found")

        'Loop through the instances of the server class.
        Dim instances As ManagementObjectCollection = serverClass.GetInstances()
        Dim instance As ManagementObject
        For Each instance In instances
            Console.Out.WriteLine("Instance Detected")
            Dim instProps As PropertyDataCollection = instance.Properties
            Dim prop As PropertyData
            For Each prop In instProps
                Dim name As String = prop.Name
                Dim val As Object = prop.Value
                Console.Out.Write("Property Name: " + name)
                If val Is Nothing Then
                    Console.Out.WriteLine("     Value: <null>")
                Else
                    Console.Out.WriteLine("     Value: " + val.ToString())
                End If
            Next
        Next

        Console.WriteLine("--- Press any key ---")
        Console.ReadKey()


    End Sub
End Module
using System;
using System.Management;
using System.IO;
[assembly: CLSCompliant(true)]

class Class1
{
    [STAThread]
    static void Main(string[] args)
    {
        const string WmiNamespace = @"\\<ServerName>\root\Microsoft\SqlServer\ReportServer\<InstanceName>\v10\Admin";
        const string WmiRSClass =
          @"\\<ServerName>\root\Microsoft\SqlServer\ReportServer\<InstanceName>\v10\admin:MSReportServer_ConfigurationSetting";
        ManagementClass serverClass;
        ManagementScope scope;
        scope = new ManagementScope(WmiNamespace);

        // Connect to the Reporting Services namespace.
        scope.Connect();
        // Create the server class.
        serverClass = new ManagementClass(WmiRSClass);
        // Connect to the management object.
        serverClass.Get();
        if (serverClass == null)
            throw new Exception("No class found");

        // Loop through the instances of the server class.
        ManagementObjectCollection instances = serverClass.GetInstances();

        foreach (ManagementObject instance in instances)
        {
            Console.Out.WriteLine("Instance Detected");
            PropertyDataCollection instProps = instance.Properties;
            foreach (PropertyData prop in instProps)
            {
                string name = prop.Name;
                object val = prop.Value;
                Console.Out.Write("Property Name: " + name);
                if (val != null)
                    Console.Out.WriteLine("     Value: " + val.ToString());
                else
                    Console.Out.WriteLine("     Value: <null>");
            }
        }
        Console.WriteLine("\n--- Press any key ---");
        Console.ReadKey();
    }
}

如需有關可在報表伺服器與報表管理員上讀取或是變更的屬性詳細資訊,請參閱<Reporting Services WMI 提供者程式庫>。如需有關報表伺服器特有的屬性詳細資訊,請參閱<MSReportServer_ConfigurationSetting 類別>。如需有關組態檔之預設安裝的詳細資訊,請參閱<組態檔 (Reporting Services)>屬性。