<p>Recently we had to migrate the Citrix XenApp v7.x database from SQL Server 2012 to SQL Server 2022. Here&#8217;s the tutorial on how to do this if you&#8217;re using three Citrix data stores or databases (Site, Monitoring; Logging).</p>
<p><img class="alignnone size-full wp-image-554" src="https://www.wincert.net/wp-content/uploads/2015/01/citrix.jpg" alt="Citrix Box,xenapp,citrix,server,ica,symantec,libraries,license,installer,publish,console,client,publisher,wfshell" width="720" height="340" /></p>
<ol>
<li><strong>First of all and most important step!</strong></li>
</ol>
<ul>
<li><strong>Create VM snapshots of Citrix DDC (Delivery Controllers)</strong></li>
<li><strong>Backup Citrix database/s</strong></li>
</ul>
<p>2. <strong>Get the Connection Strings for each DB.</strong></p>
<p>Run the following commands in Powershell (elevated mode) to get the DB connection strings for each of the three data stores:</p>
<p>Run the <strong>Asnp Citrix*</strong> command to load the Citrix snap-in commandlets.</p>
<p>Site Database:<br />
<strong>Get-BrokerDBConnection</strong></p>
<p>Logging Database:<br />
<strong>Get-LogDataStore</strong></p>
<p>Monitoring Database:<br />
<strong>Get-MonitorDataStore</strong></p>
<p>Write down the Connection Strings you got with the above commands (example):<br />
<strong>ConnectionString: &#8220;Server=Contoso\CITRIX;Initial Catalog=Citrix_Xenapp7_Site;Integrated Security=True&#8221;</strong></p>
<p>We&#8217;ll need this to create Powershell variables that will be used to connect DDCs to a new DB server.</p>
<p>3.<strong> Detach all DB connections from each Delivery Controller in the farm by running the following commands in Powershell (elevated mode):</strong></p>
<p>Set-AcctDBConnection -DBConnection $null<br />
Set-AnalyticsDBConnection -DBConnection $null<br />
Set-AppLibDBConnection -DBConnection $null<br />
Set-BrokerDBConnection -DBConnection $null<br />
Set-ConfigDBConnection -DBConnection $null<br />
Set-EnvTestDBConnection -DBConnection $null<br />
Set-HypDBConnection -DBConnection $null<br />
Set-OrchDBConnection -DBConnection $null<br />
Set-ProvDBConnection -DBConnection $null<br />
Set-SfDBConnection -DBConnection $null<br />
Set-TrustDBConnection -DBConnection $null<br />
Set-MonitorDBConnection -Datastore Monitor -DBConnection $null<br />
Set-MonitorDBConnection -DBConnection $null<br />
Set-LogDBConnection -Datastore Logging -DBConnection $null<br />
Set-LogDBConnection -DBConnection $null<br />
Set-AdminDBConnection -DBConnection $null</p>
<p>Run each of these commands one by one. That&#8217;s a better approach in case you run into an error with any of these commands.</p>
<p>If you run into an error that says: <strong>The operation could not be performed because of a configuration logging error.</strong> &#8211; Run the command again with the -force switch and it should be completed successfully.</p>
<p><img class="alignnone size-full wp-image-4975" src="https://www.wincert.net/wp-content/uploads/2023/03/configuration-logging-error.png" alt="" width="832" height="188" /></p>
<p>4.<strong> Move the Databases to the new SQL Server.</strong></p>
<p>You might need help from a DB admin since you&#8217;ll have to create logins for the DDCs and give required permissions as was the case on the old DB server.</p>
<p>5. <strong>Run Powershell in elevated mode and create connection string variables for three Citrix Datastores.</strong></p>
<p># Site DB<br />
<em>$cs = &#8220;Server=<strong>Contoso\CITRIX</strong>;Initial Catalog=<strong>CitrixXenapp7_Site</strong>;Integrated Security=True&#8221;</em><br />
# Logging DB<br />
<em>$csl = &#8220;Server=<strong>Contoso\CITRIX</strong>;Initial Catalog=<strong>CitrixXenapp7_Logging</strong>;Integrated Security=True&#8221;</em><br />
# Monitor DB<br />
<em>$csm = &#8220;Server=<strong>Contoso\CITRIX</strong>;Initial Catalog=<strong>CitrixXenapp7_Monitoring</strong>;Integrated Security=True&#8221;</em></p>
<p>Replace bold parts with your SQL Server name and Instance name, along with the Initial Catalog name or Datastore name that we got in step 2.</p>
<p>Now run the three commands above (italic font) to set variables for Site, Logging, and Monitoring datastores.</p>
<p>6. <strong>Connect the Citrix DDCs to the new SQL server by running each of the following commands:</strong></p>
<p>Set-AdminDBConnection -DBConnection $cs<br />
Set-AcctDBConnection -DBConnection $cs<br />
Set-AnalyticsDBConnection -DBConnection $cs<br />
Set-AppLibDBConnection -DBConnection $cs<br />
Set-BrokerDBConnection -DBConnection $cs<br />
Set-ConfigDBConnection -DBConnection $cs<br />
Set-EnvTestDBConnection -DBConnection $cs<br />
Set-HypDBConnection -DBConnection $cs<br />
Set-OrchDBConnection -DBConnection $cs<br />
Set-ProvDBConnection -DBConnection $cs<br />
Set-SfDBConnection -DBConnection $cs<br />
Set-TrustDBConnection -DBConnection $cs<br />
Set-LogDBConnection -DBConnection $cs<br />
Set-LogDBConnection -Datastore Logging -DBConnection $null<br />
Set-LogDBConnection -Datastore Logging -DBConnection $csl<br />
Set-MonitorDBConnection -DBConnection $cs<br />
Set-MonitorDBConnection -Datastore Monitor -DBConnection $null<br />
Set-MonitorDBConnection -Datastore Monitor -DBConnection $csm</p>
<p>Once done, restart each DDC and try to run the Studio to check that everything is working properly.</p>
<p>In the left pane of the Citrix studio administration console, select Configuration to confirm that each of the three data stores is now connected to the new SQL Server.</p>
<p>All the connection strings that we added in step 6. could be found in Windows Registry on DDC at the following path:</p>
<p><strong>HKLM\SOFTWARE\Citrix\XDservices and HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\DesktopServer\DataStore\Connections\Controller</strong></p>
<p>Comments are welcome!</p>