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

  • CTX128365
  • Created onMar 26, 2014
  • Updated onApr 09, 2014
Article Topic Configuration, Migration, Third Party


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


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: 

    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

  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: 








  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;Database= dbname;Trusted_Connection=True"
      Set-AcctDBConnection -DBConnection "Server= dbserver;Database= dbname;Trusted_Connection=True"
      Set-HypDBConnection -DBConnection "Server= dbserver;Database= dbname;Trusted_Connection=True"
      Set-ProvDBConnection -DBConnection "Server= dbserver;Database= dbname;Trusted_Connection=True"
      Set-PvsVmDBConnection -DBConnection "Server= dbserver;Database= dbname;Trusted_Connection=True"
      Set-BrokerDBConnection -DBConnection "Server= dbserver;Database= 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.


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 of 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 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 code.

Automatic translation

Important: This article was translated by an automatic translation system (also referred to as Machine Translation, or MT) and has not been translated or reviewed by people. Citrix offers a machine translated version of this article to allow for greater access to the support content. However, automatic translation is not always perfect and may contain errors of vocabulary, syntax or grammar. Citrix is not responsible for inconsistencies, errors or damage incurred as a result of the use of MT articles from our customers.Thank you.
Click here to see the English version of this article.
Was this helpful?
Thank you for your feedback

Share your comments or find out more about this topic

Citrix Forums