[英]Reporting Services: Getting reporting services path
我有一份報告列表,這些報告正在使用程序集進行本地化。 這些程序集應放在報表服務的安裝路徑上。 部署的一項任務是從.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 \\
假設您的實例名稱一致( MSRS10_50.MSSQLSERVER
),請在此注冊表位置中檢查SQLPath
項:
HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft SQL Server\\MSRS10_50.MSSQLSERVER\\Setup
如果需要,請查看此SO帖子以獲取有關閱讀注冊表的幫助。
好吧,我將粘貼我的代碼以便共享:)(控制台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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.