This article describes how to convert an existing operational XenDesktop 7 site to use a mirrored SQL Server database.
Use of a mirrored database is the option of choice where high-availability of a site is important.
The required re-configuration of the site and suggested subsequent verification of the database failover behavior are covered. However, it is assumed that the reader is familiar with the steps required to re-configure the underlying database as a mirrored database. This information is covered in various Microsoft articles, for example http://technet.microsoft.com/en-us/library/bb510479.aspx.
XenDesktop 7 supports use of SQL Server 2012 Service Pack 1, and SQL Server 2008 R2 Service Pack 2.
Use of SQL Server mirroring requires two licensed installations of SQL Server (the principal and mirror). One of these servers might be the one already in use by the XenDesktop site, although it does not need to be.
Note: SQL Server Express Edition cannot be used in the role of either principal or mirror.
For automatic failover support, a further SQL Server installation is required (the witness). This server might be an SQL Server Express Edition installation.
The recommended mode of mirroring operation is high-safety with automatic failover (synchronous). If automatic failover is not required, then high-safety without automatic failover (synchronous) is also acceptable.
Because all XenDesktop services in the site must be reconfigured, it is recommended that all site controllers are available and operational before attempting any configuration changes.
The site will be unavailable during reconfiguration of the database, although existing user sessions will be unaffected. Appropriate downtime for the site should be scheduled to allow for the reconfiguration.
Use of all the XenDesktop service SDKs is required. A machine, which can be one of the site controllers, must be available that has all the SDKs installed and registered in a PowerShell window. To make use of the PowerShell scripts present in this article also requires the machine to have the standard SQL Server SQLCMD utility installed locally.
The user performing the reconfiguration requires full administrative XenDesktop site privileges. In addition, reconfiguration of the database itself requires sysadmin privileges on all database servers involved.To start with, the DB connectivity will be tested. Also prior to reconfiguring the database, all XenDesktop services in the site must be disconnected from the current database. This is done by clearing the database connection strings, which places all services into a quiescent state. This can be achieved using the following PowerShell script:
Note: It is assumed that the Broker PowerShell SDK Snap-in has already been used to contact the site being reconfigured so its initial default admin address is set to one of the controllers in that site. If this has not been done, the XenDesktop PowerShell SDK Snap-in should be loaded by running Add-PSSnapin Citrix* from within PowerShell.
If the database used prior to the configuration of mirroring forms the principal of the new-mirrored configuration then only the controller logons are required to be added to the new mirror server. Where both database servers in the mirrored pair are new, logons must be created on both.
Suitable logons can be created using the Broker PowerShell SDK and SQLCMD as shown. Substitute the name of the database server on which the logons are to be created and the name of the target database as required:
$PrimaryDB= 'FQDN name of the primary DB within quotes' $mirrorDB = 'FQDN name of the mirror DB within quotes' $dbName = 'Name of the XD database within quotes' $controllers = Get-BrokerController | %{$_.DNSName} foreach ($controller in $controllers) { Write-Host "Make login for $controller on $mirrorServer ..." Get-BrokerDBSchema -DatabaseName $dbName -ScriptType Login -AdminAddress $controller > add-login.sql sqlcmd -S $mirrorDB -Q ':r add-login.sql' }
# In Maintenance Window , Failover to the Mirror and run the following to test connectivity
$cs = "Data Source=$PrimaryDB; Failover Partner=$MirrorDB; Initial Catalog=$dbName; Integrated Security=True; Network=dbmssocn" $controllers = Get-BrokerController | %{$_.DNSName} foreach ($controller in $controllers) { Write-Host "Testing controller $controller ..." Test-ConfigDBConnection -DBConnection $cs -AdminAddress $Controller Test-AcctDBConnection -DBConnection $cs -AdminAddress $Controller Test-HypDBConnection -DBConnection $cs -AdminAddress $Controller Test-ProvDBConnection -DBConnection $cs -AdminAddress $Controller Test-BrokerDBConnection -DBConnection $cs -AdminAddress $Controller Test-EnvTestDBConnection -DBConnection $cs -AdminAddress $Controller Test-SfDBConnection -DBConnection $cs -AdminAddress $Controller Test-MonitorDBConnection -DBConnection $cs -AdminAddress $Controller Test-MonitorDBConnection -DataStore Monitor -DBConnection $cs -AdminAddress $Controller Test-AdminDBConnection -DBConnection $cs -AdminAddress $Controller Test-LogDBConnection -DBConnection $cs -AdminAddress $Controller Test-LogDBConnection -Datastore Logging -DBConnection $cs -AdminAddress $Controller }
For version 7.6, also execute "Test-AnalyticsDBConnection -DBConnection $cs -AdminAddress $controller".
# Now set the DB connections to null.
$controllers = Get-BrokerController | %{$_.DNSName} foreach ($controller in $controllers) { Write-Host "Disconnect controller $controller ..." Set-ConfigDBConnection -DBConnection $null -AdminAddress $Controller Set-AcctDBConnection -DBConnection $null -AdminAddress $Controller Set-HypDBConnection -DBConnection $null -AdminAddress $Controller Set-ProvDBConnection -DBConnection $null -AdminAddress $Controller Set-BrokerDBConnection -DBConnection $null -AdminAddress $Controller Set-EnvTestDBConnection -DBConnection $null -AdminAddress $Controller Set-SfDBConnection -DBConnection $null -AdminAddress $Controller Set-MonitorDBConnection -Datastore Monitor -DBConnection $null -AdminAddress $Controller reset-MonitorDataStore -DataStore Monitor Set-MonitorDBConnection -DBConnection $null -AdminAddress $Controller Set-LogDBConnection -DataStore Logging -DBConnection $null -AdminAddress $Controller reset-LogDataStore -DataStore Logging Set-LogDBConnection -DBConnection $null -AdminAddress $Controller Set-AdminDBConnection -DBConnection $null -AdminAddress $Controller }
For version 7.6, also execute “Set-AnalyticsDBConnection -DBConnection $null -AdminAddress $controller”.
Note: The variable $controllers obtained in the preceding script is required as input to the PowerShell scripts shown later in this article. Ideally, the scripts should be run in the same PowerShell window. However, if this is not possible, the variable is simply an array containing the DNS names of all the controllers in the site.
The following commands needs to be executed only on one DDC. Do not run them when you are configuring DB mirroring on other DDCs within the same site.
Set-MonitorDBConnection -DataStore Monitor -DBConnection $null -AdminAddress $Controller
Set-LogDBConnection -Datastore Logging -DBConnection $null -AdminAddress $Controller
Set-MonitorDBConnection -DataStore Monitor -DBConnection $cs -AdminAddress $Controller
Set-LogDBConnection -Datastore Logging -DBConnection $cs -AdminAddress $Controller
After the services have been disconnected from the database, the underlying database can be reconfigured as a mirrored database. As far as the XenDesktop site is concerned, it is not important whether the existing database becomes the initial principal database of the new configuration, or whether a completely new-mirrored configuration is created – potentially using entirely different database servers. The only critical point is that the original content of the XenDesktop site database is present in the newly mirrored database.
Note the following points when the existing database is intended to be reused directly as the initial principal in the mirrored configuration:
If the database was originally created using Desktop Studio, its recovery model is set to Simple. This must be changed to Full before it can be mirrored.
If the database was created using Quick Deploy, it is using a local installation of SQL Server Express Edition.
This edition of the server does not support mirroring. In this case, the database must be backed-up and restored on a different SQL Server installation, which is running a suitable non-Express Edition.
Mirroring a database that uses a fixed, non-default port is problematic. Citrix recommends that mirrored databases be hosted by database engines using the default port 1433.
After setting up the mirrored database, and before continuing, verify the basic failover operation of the database. This can be done through SQL Server Management Studio (SSMS) using the Failover option available from the database properties Mirroring dialog.
In standard operation, the two databases should be shown in states (Principal, Synchronized) and (Mirror, Synchronized/Restoring…). Selecting the Failover option in the database mirroring properties dialog should cause the two databases to switch roles.
After the mirrored database is configured and its basic failover behavior verified, the XenDesktop services must be configured to use the new database. This entails:
Note the following points:
The final step of the reconfiguration is to re-establish the connections from the XenDesktop services to the mirrored database. This requires a revised connection string to be distributed to all the service instances. An example connection string suitable for a mirrored database is:
"Data Source=$PrimaryDB; Failover Partner=$MirrorDB; Initial Catalog=$dbName; Integrated Security=True; Network=dbmssocn"
Citrix recommends the use of the Network=dbmssocn option with mirrored databases. This option enforces use of the TCP provider for communication with both database servers by the XenDesktop services; this provider is optimized for use with mirroring. Also, note that:
The new connection string can be applied to all services in the site using the XenDesktop PowerShell SDK as shown in the following section. Substitute the new connection string value as required. Applying the connection string implicitly re-enables all the XenDesktop services; the site resumes operation from its state at the time when the services were originally disconnected:
$cs = '<new connection string>' foreach ($controller in $controllers) { Write-Host "Reconnect controller $controller ..." Set-AdminDBConnection -DBConnection $cs -AdminAddress $Controller Set-LogDBConnection -DBConnection $cs -AdminAddress $Controller Set-ConfigDBConnection -DBConnection $cs -AdminAddress $Controller Set-AcctDBConnection -DBConnection $cs -AdminAddress $Controller Set-HypDBConnection -DBConnection $cs -AdminAddress $Controller Set-ProvDBConnection -DBConnection $cs -AdminAddress $Controller Set-BrokerDBConnection -DBConnection $cs -AdminAddress $Controller Set-EnvTestDBConnection -DBConnection $cs -AdminAddress $Controller Set-SfDBConnection -DBConnection $cs -AdminAddress $Controller Set-MonitorDBConnection -DBConnection $cs -AdminAddress $Controller Set-MonitorDBConnection -DataStore Monitor -DBConnection $cs -AdminAddress $Controller Set-LogDBConnection -Datastore Logging -DBConnection $cs -AdminAddress $Controller }
For version 7.6, also execute Set-AnalyticsDBConnection -DBConnection $cs -AdminAddress $controller
Just in case, if an error pops-up as specified in the following section while executing the preceding command, the appropriate connection string value has to be emptied.
Set-AdminDBConnection : The operation could not be performed because of a configuration logging error.
At line:16 char:22
+ Set-AdminDBConnection <<<< -DBConnection $null -AdminAddress $Controller + CategoryInfo : InvalidOperation: (:) [Set-AdminDBConnection], InvalidOperationException + FullyQualifiedErrorId : Citrix.XDPowerShell.Status.ConfigurationLoggingError,Citrix.DelegatedAdmin.Sdk.Cmdlets.DataStore.Commands.SetAdminDBConnectionCommand
The connection string value has to be manually emptied in the registry as specified in the following section:
Caution! Refer to the Disclaimer at the end of this article before using Registry Editor.
Browse to HKLM\Software\Citrix\XDservices. Based on the specific service connection that failed during execution, the appropriate connection string value has to be emptied.
For example, if the AdminDBConnection failed during execution as specified in the preceding section, empty the ConnectionString value under HKLM\Software\Citrix\XDservices\DAS\Datastore\Connections.
If Virtual Delivery Agents were registered and user sessions active at the time when the services were disconnected, there is a period of several minutes following the resumption of operation where the site data recorded in the database is resynchronized with the current state of the active Virtual Delivery Agents and any user sessions. This is an expected behavior; no further corrective action is required.
Citrix strongly recommends that you verify the correct failover behavior of the XenDesktop site with respect to the mirrored database. It is important that all the following test steps are successful:
Because the connection strings used are the same for all services, it should be sufficient to select a single service instance for test purposes. In the following example test sequence, an arbitrary broker service instance within the site is used:
$cs = Get-BrokerDBConnection Set-BrokerDBConnection –DBConnection $null Set-BrokerDBConnection –DBConnection $cs Get-BrokerServiceStatus
With a correctly functioning database, the output from the preceding script is:
DBUnconfigured OK OK
To verify the correct interaction between the XenDesktop site and the mirrored database, use the following sequences of tests.
First, verify that the service can successfully connect to both database servers using the information present in the connection string as the service starts up:
Failures in the results from the preceding test tend to indicate errors in the configuration of the XenDesktop site or its connectivity to the database servers. Possible errors might include:
If the preceding tests show the expected results, verify that the services automatically follow the active database between servers when a database failover is triggered:
Assuming the first tests showed that connectivity to both database servers is OK following a service restart, errors in these tests tend to indicate problems in the configuration of the database mirroring itself. For example, attempting to use non-default fixed ports for the database instances can cause the services to successfully failover from the server specified in the connection string as the failover partner to the to one specified as the data source, but not in the other direction.
Citrix Documentation - Update database connection strings when using SQL Server high availability solutions