How to Move Existing XenDesktop 5.x Database to New SQL Server

How to Move Existing XenDesktop 5.x Database to New SQL Server

book

Article ID: CTX128365

calendar_today

Updated On:

Description

This article describes how to move an existing XenDesktop database from one SQL server to another.


Instructions

Complete the following procedure to move an existing XenDesktop database from one SQL server to another: 

  1. Disconnect all Services from the existing database:
    1. On each Desktop Delivery Controller (DDC) in the site, start PowerShell using the Run as administrator option.

    2. Copy and paste the following code into the PowerShell window:

      asnp Citrix.*
      Set-ConfigDBConnection -DBConnection $null
      Set-AcctDBConnection -DBConnection $null
      Set-HypDBConnection -DBConnection $null
      Set-ProvDBConnection -DBConnection $null
      Set-PvsVmDBConnection -DBConnection $null
      Set-BrokerDBConnection -DBConnection $null
    3. Leave the PowerShell window open for Step 4.

  2. Back up and restore the database: 
    Note: Do a get-configDBConnection beforehand to get the name of the SQL database, because it may not always be called CitrixXenDesktopDB

    For SQLExpress installations, run the following command at the cmd prompt on the DDC that contains the database: 

    sqlcmd -S LOCALHOST\SQLEXPRESS -q "Backup Database CitrixXenDesktopDB to disk = 'database-backup-location-directory-path' (example: C:\backup\test.bak)

    For more information regarding backing up and restoring databases, see http://msdn.microsoft.com/en-us/library/ms190436.aspx.

  1. Create Machine logins for all DDCs on the new database server:

    1. ​Start SQL Server Management Studio or SQLCMD on the SQL server housing the restored database.

    2. XenDes​ktop 5.x uses machine accounts of the DDC servers to access the database directly. Create machine account logins for each of the DDCs in the site.

    3. Each of the machine accounts should have their Database role membership set to the following roles: 

      ADIdentitySchema_ROLE

      chr_Broker

      chr_Controller

      ConfigurationSchema_ROLE

      DesktopUpdateManagerSchema_ROLE

      HostingUnitServiceSchema_ROLE

      MachinePersonalitySchema_ROLE

  1. Redirect DDCs to the new database:
    1. At each DDC, copy and paste the following lines into the open PowerShell window where <dbserver> is the name of your SQL server and <dbname> is the name of the XenDesktop database:

      Set-ConfigDBConnection -DBConnection "Server= dbserver;Initial Catalog= dbname;Trusted_Connection=True"
      Set-AcctDBConnection -DBConnection "Server= dbserver;Initial Catalog= dbname;Trusted_Connection=True"
      Set-HypDBConnection -DBConnection "Server= dbserver;Initial Catalog= dbname;Trusted_Connection=True"
      Set-ProvDBConnection -DBConnection "Server= dbserver;Initial Catalog= dbname;Trusted_Connection=True"
      Set-PvsVmDBConnection -DBConnection "Server= dbserver;Initial Catalog= dbname;Trusted_Connection=True"
      Set-BrokerDBConnection -DBConnection "Server= dbserver;Initial Catalog= dbname;Trusted_Connection=True"

      Note: If you are not using the default SQL Server instance, the Server= dbserver element should be specified as Server= dbserver\instancename. If you do not specify the instance name, you might see a message of Failed rather than OK when running the various preceding commands.

  1. Start Desktop Studio to confirm that your site is fully operational.

    Note: It is important to verify that all of the Set-<service>DBConnection commands mentioned have returned a result of OK. If a result other than OK is returned for any of these commands, it might be necessary to enable logging or tracing to determine the cause of the connection failure.

The XDDBDiag utility can be used to verify the consistency of your database after the move.

If any Virtual Desktop Agents were running when the DDC services were shut down in Step 1, then it could take up to 10 minutes before the Virtual Desktop Agents re-register. No other action is necessary.

Note: The preceding procedure and PowerShell commands must be run on every DDC in the Farm. If not, the Desktop Studio will not open.

Environment

The above mentioned sample code is provided to you as is with no representations, warranties or conditions of any kind. You may use, modify and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES WHATSOEVER, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) the sample code may exhibit errors, design flaws or other problems, possibly resulting in loss of data or damage to property; (b) it may not be possible to make the sample code fully functional; and (c) Citrix may, without notice or liability to you, cease to make available the current version and/or any future versions of the sample code. In no event should the code be used to support ultra-hazardous activities, including but not limited to life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS WILL BE LIABLE, UNDER BREACH OF CONTRACT OR ANY OTHER THEORY OF LIABILITY, FOR ANY DAMAGES WHATSOEVER ARISING FROM USE OF THE SAMPLE CODE, INCLUDING WITHOUT LIMITATION DIRECT, SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Although the copyright in the code belongs to Citrix, any distribution of the sample code should include only your own standard copyright attribution, and not that of Citrix. You agree to indemnify and defend Citrix against any and all claims arising from your use, modification or distribution of the sample code.

Issue/Introduction

This article describes how to move an existing XenDesktop database from one SQL server to another.

Additional Information

For XenDesktop 7.x - How to Migrate XenDesktop Database to New SQL Server

CTX128075 - XDDBDiag for XenDesktop

CTX127254 - XenDesktop 5.6 SDK Cmdlet Help

CTX114501 – Supported Databases for Citrix Products