This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Community Hub.
In this article, I will explain how to change the collation for your Azure SQL Managed Instance when the following scenario is encountered:
You try to change the database collation with the following T-SQL:
And it fails with the following message:
Steps in brief:
- Export the database to bacpac using SQLPackage.
- Modify the collation by editing the model.xml file.
- Import the database using SQLPackage and overriding the model.xml path.
- Change the database name or modify app connection string to use the new database.
Considerations:
- Schedule a maintenance window for your application during the process and stop the workload to prevent data loss.
- Ensure you have the latest SQLPackage version: Download and install SqlPackage - SQL Server | Microsoft Learn
- Review the different connection strings depending on the connection method outlined in these examples: SqlPackage Export - SQL Server | Microsoft Learn
- This article applies to Azure SQL DB and Azure SQL Managed Instance.
Steps in details:
- Start the maintenance window for your application.
- Export the database using SQLPackage:
- Rename the *.bacpac file to *.zip so you can open it with the file explorer:
- Copy the model.xml to a local folder “C:\Temp\model.xml”.
- Edit the “C:\Temp\model.xml” with the desired collation and save the file.
For example:
<Property Name="Collation" Value="Thai_CI_AS" />
- Rename the file extension modified in step 3 from *.zip back to *.bacpac.
- Run the import using sqlpackage.exe. Use the flag /ModelFilePath:C:\Temp\model.xml to override the model.xml in the .bacpac file.
- When the import operation is completed, change the database name, or modify the application connection string to use the new database name. You can also check the new collation setting in the database properties using SSMS:
- Stop the maintenance window for your application and run the workload. Ensure that the application is working as expected.
