Home
%3CLINGO-SUB%20id%3D%22lingo-sub-369182%22%20slang%3D%22en-US%22%3EHow%20to%20Migrate%20Azure%20SQL%20Database%20to%20Azure%20SQL%20Managed%20Instance%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-369182%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Jan%2028%2C%202019%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20The%20latest%20version%20of%20SQLPackage%20supports%20migration%20to%20Azure%20SQL%20Managed%20Instance%20(MI)%20from%20multiple%20SQL%20sources%20such%20as%20Azure%20SQL%20Database.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3EExport%3A%20%3CBR%20%2F%3E%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20Following%20the%20below%20steps%2C%20you%20can%20export%20a%20SQL%20database%20using%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fsql%2Ftools%2Fsqlpackage%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20SQLPackage%20%3C%2FA%3E%20command-line%20utility.%20If%20possible%2C%20use%20a%20workstation%20that%20has%20access%20to%20the%20Azure%20SQL%20Database%20and%20the%20MI%20to%20avoid%20having%20to%20move%20the%20exported%20bacpac%20to%20a%20workstation%20that%20has%20access%20to%20your%20destination%20MI.%20%3CBR%20%2F%3E%3COL%3E%3CBR%20%2F%3E%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ftools%2Fsqlpackage-download%3Fview%3Dsql-server-2017%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EDownload%20%3C%2FA%3E%20and%20run%20the%20DacFramework.msi%20installer%20for%20Windows.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EOpen%20a%20new%20Command%20Prompt%20window%2C%20and%20run%20the%20following%20command%20%3CEM%3E%20%3CEM%3E%20%3CEM%3E%20%3CSTRONG%3E%20%3CBR%20%2F%3E%20cd%20C%3A%5CProgram%20Files%5CMicrosoft%20SQL%20Server%5C150%5CDAC%5Cbin%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FEM%3E%3C%2FEM%3E%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3ERun%20the%20following%20command%20to%20export%20the%20SQL%20database%3A%20%3CBR%20%2F%3E%20%3CEM%3E%20%3CSTRONG%3E%20sqlpackage.exe%20%2Fa%3AExport%20%2FSourceServerName%3Aservername.database.windows.net%20%2FSourceDatabaseName%3Adbname%20%2FSourceUser%3Ausername%20%2FSourcePassword%3Apassword%20%2FTargetFile%3AC%3A%5CUsers%5Cuser%5CDesktop%5Cbackup150.bacpac%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FOL%3E%3CBR%20%2F%3E%20%3CEM%3E%20In%20the%20above%20command%2C%20we%20will%20export%20the%20database%20%E2%80%9Cdbname%E2%80%9D%20from%20server%20%E2%80%9Cservername%E2%80%9D%20to%20a%20local%20file%20named%20%E2%80%9Cbackup150.bacpac%E2%80%9D.%20You%20will%20want%20to%20adjust%20these%20values%20to%20match%20your%20setup.%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3EImport%3A%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20If%20the%20environment%20that%20contains%20the%20exported%20bacpac%20file%20does%20not%20have%20access%20to%20the%20destination%20MI%2C%20move%20the%20exported%20bacpac%20file%20%E2%80%9Cbackup150.bacpac%E2%80%9D%20to%20an%20environment%20that%20can%20access%20your%20Azure%20SQL%20MI.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Following%20the%20below%20steps%2C%20you%20can%20import%20the%20bacpac%20into%20an%20Azure%20SQL%20Managed%20Instance%20using%20the%20same%20SQLPackage%20utility%20for%20export.%20If%20you%20have%20already%20done%20step%201%20and%202%20on%20your%20current%20environment%20from%20the%20export%20above%2C%20please%20skip%20to%20step%203%20to%20run%20the%20import.%20%3CBR%20%2F%3E%3COL%3E%3CBR%20%2F%3E%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ftools%2Fsqlpackage-download%3Fview%3Dsql-server-2017%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EDownload%20%3C%2FA%3E%20and%20run%20the%20DacFramework.msi%20installer%20for%20Windows.%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3EOpen%20a%20new%20Command%20Prompt%20window%2C%20and%20run%20the%20following%20command%20%3CBR%20%2F%3E%20%3CEM%3E%20%3CSTRONG%3E%20cd%20C%3A%5CProgram%20Files%5CMicrosoft%20SQL%20Server%5C150%5CDAC%5Cbin%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3E%3CEM%3E%20%3CSTRONG%3E%20%3C%2FSTRONG%3E%20%3C%2FEM%3E%20Run%20the%20following%20command%20to%20import%20into%20the%20Managed%20Instance%20%3CBR%20%2F%3E%20%3CEM%3E%20%3CSTRONG%3E%20sqlpackage.exe%20%2Fa%3AImport%20%2FTargetServerName%3AManagedInstancename.appname.database.windows.net%20%2FTargetDatabaseName%3Adbname%20%2FTargetUser%3Ausername%20%2FTargetPassword%3Apassword%20%2FSourceFile%3AC%3A%5CUsers%5Cuser%5CDesktop%5Cbackup150.bacpac%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3E%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FOL%3E%3CBR%20%2F%3E%3COL%3E%0A%20%20%3C%2FOL%3E%3CBR%20%2F%3E%20%3CEM%3E%20%3CBR%20%2F%3E%20In%20the%20above%20command%2C%20we%20will%20import%20the%20database%20%E2%80%9Cdbname%E2%80%9D%20into%20your%20destination%20MI%20%E2%80%9CManagedInstancename%E2%80%9D%20from%20the%20bacpac%20named%20%E2%80%9Cbackup150.bacpac%E2%80%9D.%20You%20will%20want%20to%20adjust%20these%20values%20to%20match%20your%20setup.%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Please%20note%20that%20older%20DACfx%20versions%20than%20%E2%80%9C18.0%E2%80%9D%20do%20not%20support%20migration%20to%20Azure%20SQL%20Managed%20Instance%20and%20to%20ensure%20latest%20compatibility%2C%20please%20make%20sure%20that%20you%20are%20using%20the%20latest%20version%20of%20SQLPackage.%20Using%20older%20version%20could%20cause%20errors%20such%20as%20listed%20below%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20***%20Error%20importing%20database%3ACould%20not%20import%20package.%20%3CBR%20%2F%3E%20Unable%20to%20connect%20to%20master%20or%20target%20server%20%E2%80%98database%20name%E2%80%99.%20You%20must%20have%20a%20user%20with%20the%20same%20password%20in%20master%20or%20target%20server.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Or%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20***%20Error%20importing%20database%3ACould%20not%20import%20package.%20%3CBR%20%2F%3E%20Warning%20SQL0%3A%20A%20project%20which%20specifies%20Microsoft%20Azure%20SQL%20Database%20v12%20as%20the%20target%20platform%20may%20experience%20compatibility%20issues%20with%20SQL%20Server%202014.%20%3CBR%20%2F%3E%20Error%20SQL72014%3A%20.Net%20SqlClient%20Data%20Provider%3A%20Msg%2041918%2C%20Level%2016%2C%20State%201%2C%20Line%202%20Specifying%20files%20and%20filegroups%20in%20CREATE%20DATABASE%20statement%20is%20not%20supported%20on%20SQL%20Database%20Managed%20Instance.%20%3CBR%20%2F%3E%20Error%20SQL72045%3A%20Script%20execution%20error.%26nbsp%3B%20The%20executed%20script%3A%20%3CBR%20%2F%3E%20CREATE%20DATABASE%20%5B%24(DatabaseName)%5D%20%3CBR%20%2F%3E%20ON%20%3CBR%20%2F%3E%20PRIMARY(NAME%20%3D%20%5B%24(DatabaseName)%5D%2C%20FILENAME%20%3D%20N'%24(DefaultDataPath)%24(DefaultFilePrefix)_Primary.mdf')%20%3CBR%20%2F%3E%20LOG%20ON%20(NAME%20%3D%20%5B%24(DatabaseName)_log%5D%2C%20FILENAME%20%3D%20N'%24(DefaultLogPath)%24(DefaultFilePrefix)_Primary.ldf')%20COLLATE%20SQL_Latin1_General_CP1_CI_AS%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-369182%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Jan%2028%2C%202019%20The%20latest%20version%20of%20SQLPackage%20supports%20migration%20to%20Azure%20SQL%20Managed%20Instance%20(MI)%20from%20multiple%20SQL%20sources%20such%20as%20Azure%20SQL%20Database.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-369182%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eazure%20sql%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ebacpac%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eimportexport%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Emanaged%20instance%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMigration%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft
First published on MSDN on Jan 28, 2019
The latest version of SQLPackage supports migration to Azure SQL Managed Instance (MI) from multiple SQL sources such as Azure SQL Database.

Export:

Following the below steps, you can export a SQL database using the SQLPackage command-line utility. If possible, use a workstation that has access to the Azure SQL Database and the MI to avoid having to move the exported bacpac to a workstation that has access to your destination MI.

  1. Download and run the DacFramework.msi installer for Windows.

  2. Open a new Command Prompt window, and run the following command
    cd C:\Program Files\Microsoft SQL Server\150\DAC\bin

  3. Run the following command to export the SQL database:
    sqlpackage.exe /a:Export /SourceServerName:servername.database.windows.net /SourceDatabaseName:dbname /SourceUser:username /SourcePassword:password /TargetFile:C:\Users\user\Desktop\backup150.bacpac


In the above command, we will export the database “dbname” from server “servername” to a local file named “backup150.bacpac”. You will want to adjust these values to match your setup.


Import:
If the environment that contains the exported bacpac file does not have access to the destination MI, move the exported bacpac file “backup150.bacpac” to an environment that can access your Azure SQL MI.

Following the below steps, you can import the bacpac into an Azure SQL Managed Instance using the same SQLPackage utility for export. If you have already done step 1 and 2 on your current environment from the export above, please skip to step 3 to run the import.

  1. Download and run the DacFramework.msi installer for Windows.

  2. Open a new Command Prompt window, and run the following command
    cd C:\Program Files\Microsoft SQL Server\150\DAC\bin

  3. Run the following command to import into the Managed Instance
    sqlpackage.exe /a:Import /TargetServerName:ManagedInstancename.appname.database.windows.net /TargetDatabaseName:dbname /TargetUser:username /TargetPassword:password /SourceFile:C:\Users\user\Desktop\backup150.bacpac





In the above command, we will import the database “dbname” into your destination MI “ManagedInstancename” from the bacpac named “backup150.bacpac”. You will want to adjust these values to match your setup.






Please note that older DACfx versions than “18.0” do not support migration to Azure SQL Managed Instance and to ensure latest compatibility, please make sure that you are using the latest version of SQLPackage. Using older version could cause errors such as listed below:

*** Error importing database:Could not import package.
Unable to connect to master or target server ‘database name’. You must have a user with the same password in master or target server.

Or

*** Error importing database:Could not import package.
Warning SQL0: A project which specifies Microsoft Azure SQL Database v12 as the target platform may experience compatibility issues with SQL Server 2014.
Error SQL72014: .Net SqlClient Data Provider: Msg 41918, Level 16, State 1, Line 2 Specifying files and filegroups in CREATE DATABASE statement is not supported on SQL Database Managed Instance.
Error SQL72045: Script execution error.  The executed script:
CREATE DATABASE [$(DatabaseName)]
ON
PRIMARY(NAME = [$(DatabaseName)], FILENAME = N'$(DefaultDataPath)$(DefaultFilePrefix)_Primary.mdf')
LOG ON (NAME = [$(DatabaseName)_log], FILENAME = N'$(DefaultLogPath)$(DefaultFilePrefix)_Primary.ldf') COLLATE SQL_Latin1_General_CP1_CI_AS;