title: RSConfig generates a Dsn Connection String doesn't work
body: <p><strong>TL;DR</strong>. </p>
  
  <p>Repro steps, take a backup of your <code>C:\Program Files\Microsoft SQL Server\MSRS13.SSRS\Reporting Services\ReportServer\RsReportServer.config</code> </p>
  
  <p>Run this command to update the connection string in SSRS's config:</p>
  
  <pre><code>C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn&gt;rsconfig -c -s &lt;ServerName&gt; -i &lt;instanceNameIfNotDefault&gt; -d "reportserver$ssrs" -a SQL -u sa -p "YourSAPassword" -t
  </code></pre>
  
  <p>Now browse to the SSRS website and it doesn't work! To fix it either restore your config file or run through the SSRS GUI tool and it works!</p>
  
  <p>How does the RsConfig utility work?</p>
  
  <hr>
  
  <p><strong>Background</strong><br>
  After I install SSRS on an Windows 2016 Server and restore the 2 databases I need to change the Connection String in SSRS configuration file to point to the new SQL server name/instance.</p>
  
  <p><a href="https://i.stack.imgur.com/T7c75.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/T7c75.png" alt="enter image description here"></a></p>
  
  <p><strong>Problem</strong><br>
  When I try to change the encrypted Connection String in <code>C:\Program Files\Microsoft SQL Server\MSRS13.SSRS\Reporting Services\ReportServer\RsReportServer.config</code> file using the RSConfig utility:</p>
  
  <pre><code>C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn&gt;rsconfig -c -s Server0012 -i SSRS -d "reportserver$ssrs" -a SQL -u sa -p "P@ssw0rd!" -t
  </code></pre>
  
  <p>It changes the Dsn Connection String in the RsReportServer.config. </p>
  
  <p><strong>Before:</strong>
  &lt;Dsn>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAE+tJc/4Vs0a0fdH0tCY8kgQAAAAiAAAAUgBlAHAAbwByAHQAaQBuAGcAIABTAGUAcgB2AGUAcgAAABBmAAAAAQAAIAAAAC2DBxZFsfVB16r0e3......
  *</p>
  
  <p><strong>After:</strong>
  &lt;Dsn>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAE+tJc/4Vs0a0fdH0tCY8kgQAAAAiAAAAUgBlAHAAbwByAHQAaQBuAGcAIABTAGUAcgB2AGUAcgAAABBmAAAAAQAAIAAAAO2nOjFDJMo........
  *</p>
  
  <p>However after this change, browsing to the SSRS Website results in the error:</p>
  
  <blockquote>
    <p>The report server can’t connect to its database. Make sure the database is running and accessible. You can also check the report server trace log for details.</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/h0CO6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h0CO6.png" alt="enter image description here"></a></p>
  
  <p><strong>If I run the SQL Reporting Services Configuration Tool (GUI) and change the Dsn Connection String browsing to the SSRS Website works!</strong> </p>
  
  <p><a href="https://i.stack.imgur.com/R8Ynx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R8Ynx.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/gJQfn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gJQfn.png" alt="enter image description here"></a></p>
  
  <p>Obviously it changes the Dsn but I can't work out what else it does whilst the GUI tool is running. I've used ProcessMonitor and I've seen that the GUI tool does <strong>NOT</strong> use   RSConfig.exe utility, it uses itself RsConfigTool.exe! So I can't even capture command-line arguments of what the actual command/connection string should be. Also each time we change the connection string a new random one is generated so not sure how to do comparison's of actual vs expected.</p>
  
  <p>I did a WinDiff of Registry keys and apart from some encrypted hexadecimal diffs, nothing stood out.</p>
  
  <p>I run SQLProfiler and there were a bunch of grants that I have emulated in my PowerShell script, eg: </p>
  
  <pre><code>$sqls += @"
  USE [ReportServer`$SSRSTempDB]
  if not exists (select * from sysusers where issqlrole = 1 and name = 'RSExecRole')
  BEGIN
   EXEC sp_addrole 'RSExecRole'
  END;
  GO
  </code></pre>
  
  <p>My hunch is the $ sign in the SQL Database Name and the @ in the "made up/simulated" password are not getting escaped when I run the commands, eg:</p>
  
  <pre><code>$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(" ")
  &amp; "$rsConfigPath" $args
  
  Restart-Service -Force "SQL Server ($instanceName)"
  </code></pre>
  
  <p>When I run these vanilla commands in Command Prompt (no need to escape PowerShell characters):</p>
  
  <pre><code>rsconfig -c -s Server0012 -i SSRS -d "reportserver$ssrs" -a SQL -u sa -p "P@ssw0rd!"
  </code></pre>
  
  <p>It changes the Dsn Connection String but browsing to SSRS Website gives same error (above).</p>
  
  <p>How can I find out what else RsConfigTool.exe does when changing the Current Report Server Database? Or any guesses why the Connection String generated using the RSConfig Utility is out of whack - I've tried many different combinations, seems like only the RSConfigTool can actually do it?</p>
  
  <p>Note 1:<br>
  I'm scripting this all up as a DevOps project and we are baking these images with packer, so nothing can be done manually. </p>
  
  <p>Note 2:<br>
  The Machine is joined to the domain and renamed after SQL installed. So using a Configuration.ini file I don't think will work.</p>