【问题标题】:Reporting Services: Getting reporting services pathReporting Services:获取报告服务路径
【发布时间】:2013-02-19 15:28:30
【问题描述】:

我有一份报告列表,哪些正在使用要本地化的程序集。这些程序集应放置在报告服务的安装路径上。部署任务之一是将这些程序集从 .Net (vb.net) 复制到正确的路径中。

现在我们使用硬代码路径来添加程序集(带有翻译)。那么,有没有办法从 Vb.Net 获取服务器中运行的 sql 报告服务的路径?

I.E.报告服务的有效路径是:

C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer\bin

我期望得到的是这样的:

C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\

【问题讨论】:

    标签: c# vb.net reporting-services


    【解决方案1】:

    假设您的实例名称一致 (MSRS10_50.MSSQLSERVER),请检查此注册表位置中的 SQLPath 键:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Setup

    如果需要,请查看 this SO post 以获取有关读取注册表的帮助。

    【讨论】:

    • 感谢您的反馈:)。我可以假设这个键是相对于 SQL2008R2.. 但是其他版本呢?
    • 只需枚举HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft SQL Server 下注册表中以MSRS 开头的文件夹,并且应该处理所有版本。
    【解决方案2】:

    好的,我将粘贴我的代码以便分享:)(控制台 VB.Net 应用程序)

    Private Const INSTANCES As String = "SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\RS"
    Private PathToReplace As String = "SOFTWARE\Microsoft\Microsoft SQL Server\{textToReplace}\Setup"
    
    Sub Main()
    
        'For now we must be sure we have only one instance of sql reporting service
        Dim reportingInstances As List(Of String) = GetSQLReportingServicesInstances()
    
        Dim InstanceName As String = GetKeyValue(INSTANCES, reportingInstances.Item(0))
    
        Dim registryPathOfSqlReportingServices As String = PathToReplace.Replace("{textToReplace}", InstanceName)
    
        Dim pathOfSqlReportingServices As String = GetKeyValue(registryPathOfSqlReportingServices, "SQLPath")
    
        Console.WriteLine(pathOfSqlReportingServices)
    
        Console.ReadLine()
    End Sub
    
    
    Public Function GetKeyValue(ByVal RegistryPath As String, ByVal key As String) As String
    
        Dim localMachine As RegistryKey = GetRegistryParentKey()
    
        Dim windowsNTKey As RegistryKey = localMachine.OpenSubKey(RegistryPath)
    
        Return windowsNTKey.GetValue(key).ToString()
    
    End Function
    
    Public Function GetSQLReportingServicesInstances() As List(Of String)
    
        Dim listOfInstances As New List(Of String)
    
        Dim localMachine As RegistryKey = GetRegistryParentKey()
    
        Dim InstancesKey As RegistryKey = localMachine.OpenSubKey(INSTANCES)
    
        For Each InstanceKey As String In InstancesKey.GetValueNames
            listOfInstances.Add(InstanceKey)
        Next
    
        Return listOfInstances
    
    End Function
    
    
    Public Function GetRegistryParentKey() As RegistryKey
    
        Dim localMachine As RegistryKey = Nothing
    
        If (Environment.Is64BitOperatingSystem) Then
            localMachine = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64)
        Else
            localMachine = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32)
        End If
        Return localMachine
    
    End Function
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-21
      • 1970-01-01
      • 2023-01-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多