Reporting Services WMI 提供程序

Reporting Services WMI 提供程序在标准 Windows Management Instrumentation (WMI) 技术的基础上建立,用于访问企业环境中的控制和管理信息。用于 Reporting Services 的 WMI 提供程序起到实例提供程序的作用,将报表服务器 XML 配置元素映射到一组类,这些类包括您可以调用以添加、删除或修改报表服务器配置信息的方法。有关这些类的详细信息,请参阅 Reporting Services WMI 提供程序库

WMI 提供程序概述

通过在 Reporting Services 中包括的 WMI 类,可以在本地和远程计算机上控制报表服务器和报表管理器组件,提供发现网络中的哪些计算机正在运行报表服务器 Web 服务的方法,以及在扩展部署中激活报表服务器实例。系统管理员和数据库管理员可以在安装完成后使用这些类对报表服务器和报表管理器的配置进行更改,或者执行本地或远程服务器管理任务。任务包括修改报表服务器和报表服务器数据库之间的数据库连接凭据,修改报表服务器数据库的名称,以及更改定义指向报表服务器实例或报表管理器的安装路径的 URL。

为支持这些功能而安装的类如下:

用于获取与本主题中所示代码示例中的 Reporting Services 的有关信息的命名空间位于 Microsoft .NET Framework 中的 System.Management 命名空间中。System.Management 命名空间提供一组托管代码类,.NET Framework 应用程序可通过这些类访问和操作管理信息。有关使用采用 System.Management 命名空间的 Reporting Services WMI 类的详细信息,请参阅 Microsoft .NET Framework SDK 中的“使用 System.Managment 访问管理信息”。

查找报表服务器实例

如果计算机安装了某一报表服务器的多个实例,则管理员需要指向计算机上要修改其属性的准确实例。为了直接找到该实例,每个类都包含定义为键的属性。该键属性唯一标识一个报表服务器安装。定义为键的属性是 PathName 属性。此属性的值是指向 RSReportServer.config 配置文件的路径,包括该配置文件的名称。对于大多数安装,此路径与以下示例类似:

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

实例名称中的特殊字符 实例名称中的下划线 (_) 在 PathName 属性中将转换为“_5f”。例如:

  • 实例名称 = My_Instance

  • PathName 属性 = My_5fInstance

在创建 MSReportServer_ConfigurationSetting 类后,可以填充该键并搜索计算机以找到匹配该键的报表服务器或报表管理器的实例。如果找到上述实例,则用来自该实例的其余值填充管理集合。

您还可以通过填充某一集合以获取信息,并通过循环遍历管理类以显示该信息。如果从 Visual Studio .NET 运行此代码,则添加对 System.Management 的项目引用。下面的示例假定 RSReportServer.config 配置文件位于 C:\Program Files\Microsoft SQL Server\MSRS10_50.<实例名>\Reporting Services\ReportServer\bin 中。在 Microsoft Visual Studio .NET SDK 中提供针对 System.Management 类中方法的说明。

查找与您的报表服务器安装有关的信息的首选方式是枚举 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)