2

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

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

IE 报告服务的有效路径是:

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

我期望得到的是:

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

4

2 回答 2

0

假设您的实例始终命名为 ( MSRS10_50.MSSQLSERVER),请检查SQLPath此注册表位置中的键:

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

在此处输入图像描述

如果需要,请查看此 SO 帖子以获取有关阅读注册表的帮助。

于 2013-02-19T20:48:18.467 回答
0

好的,我将粘贴我的代码以共享它:)(控制台 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
于 2013-02-20T00:55:33.390 回答