一尘不染

RSConfig生成Dsn连接字符串不起作用

sql

TL; DR

复制步骤,备份您的 C:\Program Files\Microsoft SQL Server\MSRS13.SSRS\Reporting Services\ReportServer\RsReportServer.config

运行以下命令以更新SSRS的配置中的连接字符串:

C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn>rsconfig -c -s <ServerName> -i <instanceNameIfNotDefault> -d "reportserver$ssrs" -a SQL -u sa -p "YourSAPassword" -t

现在浏览到SSRS网站,它不起作用!要修复它,请还原您的配置文件或通过SSRS GUI工具运行,它可以正常工作!

RsConfig实用程序如何工作?


背景信息
在Windows 2016 Server上安装SSRS并还原2个数据库后,需要更改SSRS配置文件中的连接字符串以指向新的SQL Server名称/实例。

在此处输入图片说明

问题
当我尝试C:\Program Files\Microsoft SQL Server\MSRS13.SSRS\Reporting Services\ReportServer\RsReportServer.config使用RSConfig实用程序更改文件中的加密连接字符串时:

C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn>rsconfig -c -s Server0012 -i SSRS -d "reportserver$ssrs" -a SQL -u sa -p "P@ssw0rd!" -t

它更改RsReportServer.config中的Dsn连接字符串。

之前: AQAAANCMnd8BFdERjHoAwE / Cl + sBAAAAE + tJc /
4Vs0a0fdH0tCY8kgQAAAAiAAAAUgBlAHAAbwByAHQAaQBuAGcAIABTAGUAcgB2AGUAcgAAABBmAAAAAQAAIAAAAC2BBZF

之后: AQAAANCMnd8BFdERjHoAwE / Cl + sBAAAAE + tJc /
4Vs0a0fdH0tCY8kgQAAAAiAAAAUgBlAHAAbwByAHQAaQBuAGcAIABTAGUAcgB2AGUAcgAAABBmAAAAAQAAIAAAAO2nOjFD。

但是,在进行此更改之后,浏览到SSRS网站会导致错误:

报表服务器可以连接到其数据库。确保数据库正在运行并且可以访问。您也可以检查报表服务器跟踪日志以了解详细信息。

在此处输入图片说明

如果我运行SQL Reporting Services配置工具(GUI)并更改Dsn连接字符串,则浏览到SSRS网站就可以了!

在此处输入图片说明

在此处输入图片说明

显然,它改变了Dsn,但是在GUI工具运行时,我无法弄清楚它还能做什么。我用的ProcessMonitor和我见过的GUI工具确实
使用RSConfig.exe工具,它使用自身RsConfigTool.exe!因此,我什至无法捕获实际命令/连接字符串应该是什么的命令行参数。同样,每次我们更改连接字符串时,都会生成一个新的随机字符串,因此不确定如何进行实际值与预期值的比较。

我做了一个注册表项的WinDiff,除了一些加密的十六进制差异外,什么都没有脱颖而出。

我运行SQLProfiler,在PowerShell脚本中模拟了很多授予,例如:

$sqls += @"
USE [ReportServer`$SSRSTempDB]
if not exists (select * from sysusers where issqlrole = 1 and name = 'RSExecRole')
BEGIN
 EXEC sp_addrole 'RSExecRole'
END;
GO

我的直觉是,在运行命令时,SQL数据库名称中的$符号和“编造/模拟”密码中的@不会被转义,例如:

$MachineName = "server0012"
$instanceName = "SSRS"
$saPassword = "P@ssw0rd!"

$rsConfigPath = "C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\rsconfig.exe"
$setupArgs = -join('-c -s "', $MachineName,'" -i "', $instanceName,'" -d ','"ReportServer`$SSRS" -t -a SQL -u "sa" -p "', $saPassword,"""")

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
Write-Host $rsConfigPath $setupArgs
$args = $setupArgs.Split(" ")
& "$rsConfigPath" $args

Restart-Service -Force "SQL Server ($instanceName)"

当我在命令提示符中运行这些香草命令时(无需转义PowerShell字符):

rsconfig -c -s Server0012 -i SSRS -d "reportserver$ssrs" -a SQL -u sa -p "P@ssw0rd!"

它更改了Dsn连接字符串,但浏览到SSRS网站会出现相同的错误(上述)。

更改当前报表服务器数据库时,如何找出RsConfigTool.exe的其他功能?或有任何猜测为什么使用RSConfig
Utility生成的连接字符串不合时宜-我尝试了许多不同的组合,似乎只有RSConfigTool才能真正做到这一点?

注意1:
我将所有这些脚本编写为一个DevOps项目,并且我们正在使用打包程序来烘焙这些图像,因此无法手动完成任何操作。

注意2:
计算机已加入域,并在安装SQL之后重命名。因此,我认为使用Configuration.ini文件不起作用。


阅读 189

收藏
2021-05-16

共1个答案

一尘不染

诀窍是您需要使用PowershellInvoke-Expression命令,服务器名称必须包含实例名称,且不带引号server \
instance,并且您确实需要在RsConfig.exe命令中转义$符号:-d ','"reportserver<tilda>$ssrs"'

= ` 转义$符号的tilda键,请参见下面的脚本。

如果不使用Invoke-Expression和转义$符号,则DatabaseName称为 ReportServer 而不是
ReportServer $ SSRS

在此处输入图片说明

您可以在SSRS日志中看到以下内容:

库!WindowsService_1!30c!05/17 / 2019-03:56:29 ::
e错误:抛出Microsoft.ReportingServices.Library.ReportServerDatabaseUnavailableException:,Microsoft.ReportingServices.Library.ReportServerDatabaseUnavailableException:报表服务器无法打开与报表的连接服务器数据库。所有请求和处理都需要与数据库的连接。-–>
System.Data.SqlClient.SqlException:建立与SQL Server的连接时发生与网络相关或特定于实例的错误。
服务器未找到或无法访问。 验证实例名称正确,并且已将SQL
Server配置为允许远程连接。
(提供者:命名管道提供程序,错误:40-无法打开与SQL Server的连接)

这是我用来修复已重命名的服务器上损坏的SQL安装的脚本:

Param(
    [parameter(mandatory=$true,helpmessage="New Machine Name")]
    [string]$MachineName,

    [parameter(mandatory=$false,helpmessage="SQL Instance Name")]
    [string]$instanceName = "SSRS",

    [parameter(mandatory=$false,helpmessage="SQL SA Password")]
    [string]$saPassword = "P@ssword1"  #this is encrypted IRL
)


#1. Start the logging
Start-Transcript -Path "C:\temp\rename-ssrs-computer.txt"

#2. Change the SQL Server's name
Write-Host "Change the SQL Server Instance Name to $MachineName"


$moduleName = "SqlServer"
Import-Module $moduleName -Verbose

$sql = 'select @@SERVERNAME'
$serverNameQry = Invoke-SqlCmd -Serverinstance ".\$instanceName" -Query $sql -username "sa" -password $saPassword  -querytimeout ([int]::MaxValue)
$serverName = $serverNameQry.Column1

$sql = -join('sp_dropserver ''', $serverName,'''
GO
sp_addserver ''', $MachineName, "\", $instanceName,''',''local''
GO
')
Invoke-SqlCmd -Serverinstance ".\$instanceName" -Query $sql -username "sa" -password $saPassword  -querytimeout ([int]::MaxValue)

#3. Change the SSRS database permissions
$sqls = @()
$sqls += @"
USE master

DECLARE @AccountName nvarchar(260)
SET @AccountName = SUSER_SNAME(0x010100000000000514000000)
if not exists (select name from syslogins where name = @AccountName and hasaccess = 1 and isntname = 1)
BEGIN
EXEC sp_grantlogin @AccountName
END;
GO
"@

#..... all the SQL Profile trace outputs...#

Foreach ($sql in $sqls)
{
  Invoke-SqlCmd -Serverinstance ".\$instanceName" -Query $sql -username "sa" -password $saPassword  -querytimeout ([int]::MaxValue)
}

#4. Change all the registry key values with the AMI Original Computer Name
Write-Host "Change the SQL Server Name in the Registry to $MachineName"

$txt = -join('Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\130\Machines]
"OriginalMachineName"="',$MachineName,'"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SQL Server\90\Machines]
"OriginalMachineName"="',$MachineName,'"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SQL Server\140\Machines]
"OriginalMachineName"="',$MachineName,'"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SQL Server\130\Machines]
"OriginalMachineName"="',$MachineName,'"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Services\SSIS Server]
"GroupPrefix"="SQLServerDTSUser$',$MachineName,'"
"LName"=""
"Name"="MsDtsServer"
"Type"=dword:00000004

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SQL Server\Services\SSIS Server]
"GroupPrefix"="SQLServerDTSUser$',$MachineName,'"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Services\Report Server]
"Name"="ReportServer"
"LName"="ReportServer$"
"Type"=dword:00000006
"GroupPrefix"="SQLServerReportServerUser$',$MachineName,'$"

[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Microsoft SQL Server\Services\Report Server]
"Name"="ReportServer"
"LName"="ReportServer$"
"Type"=dword:00000006
"GroupPrefix"="SQLServerReportServerUser$',$MachineName,'$"'

)

Add-Content "C:\temp\output.reg" $txt
regedit /s "C:\temp\output.reg"


#5. Set the encrypted connection string DONT CHANGE THIS!!!
$rsConfigPath = "C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\"
$setupArgs = -join('-c -s ', $MachineName, '\' , $instanceName,' -i ', $instanceName,' -d ','"reportserver`$ssrs"', ' -t -a SQL -u sa -p "', $saPassword,'"')
Write-Host "Setup args for RSConfig $rsConfigPath $setupArgs"
Write-Host "Running RSConfig"
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
Write-Host $rsConfigPath $setupArgs

Set-Location "$rsConfigPath"
Invoke-Expression $("rsconfig.exe " + $setupArgs)

Write-Host "RSConfig Dsn complete, new Connection string under Dsn saved to rsconfig.config file."


#6. Restart the SQL Service
Write-Host "Restarting $instanceName"
Restart-Service -Force "SQL Server ($instanceName)"
Write-Host "Restarted $instanceName"


#7. Set regional format (date/time etc.) to English (Australia) - this applies to all users 
Import-Module International 
Set-Culture en-AU 
# Check language list for non-US input languages, exit if found 
$currentlist = Get-WinUserLanguageList 
$currentlist | ForEach-Object {if(($.LanguageTag -ne "en-AU") -and ($.LanguageTag -ne "en-US")){exit}} 
# Set the language list for the user, forcing English (Australia) to be the only language 
Set-WinUserLanguageList en-AU -Force 
Set-TimeZone -Name "AUS Eastern Standard Time"


# Lastly Stop the transcript (before the PC gets rebooted by the calling script).
Stop-Transcript
2021-05-16