Home
%3CLINGO-SUB%20id%3D%22lingo-sub-368871%22%20slang%3D%22en-US%22%3EExported%20database%20from%20Azure%20SQL%20failed%20to%20be%20imported%20to%20Azure%20SQL%20or%20to%20local%20SQL%20Server%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-368871%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%3E%20First%20published%20on%20MSDN%20on%20Mar%2030%2C%202017%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CH2%20id%3D%22toc-hId-1678997693%22%20id%3D%22toc-hId-1737176516%22%3E%3CSTRONG%3E%20Update%3A%20(2018-01-30)%20-%20Resolved%20%3C%2FSTRONG%3E%3C%2FH2%3E%3CBR%20%2F%3E%3CP%3EDacFX%20version%2017.4.1%20has%20been%20released%2C%20this%20version%20contains%20the%20fix%20for%20all%20of%20the%20behaviors%20related%20to%20the%20master%20key.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eyou%20can%20download%20it%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fdownload%2Fdetails.aspx%3Fid%3D56508%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20here%3C%2FA%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eto%20confirm%20you%20are%20using%20the%20correct%20version%2C%20verify%20that%20the%20file%20version%20of%20SQLPackage.exe%20is%20at%20least%2014.0.3917.1%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eand%20follow%20the%20instructions%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Fazuresqldbsupport%2F2017%2F01%2F31%2Fusing-sqlpackage-to-import-or-export-azure-sql-db%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20using%20sqlpackage%20to%20import%20or%20export%20azure%20sql%20db%3C%2FA%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3Ealternatively%20%3C%2FSTRONG%3E%20you%20use%20SSMS%2017.6%20and%20above%2C%20you%20can%20download%20it%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Fssms%2Fdownload-sql-server-management-studio-ssms%3Fview%3Dsql-server-2017%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20here%3C%2FA%3E%3C%2FP%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3ESymptoms%3A%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20When%20using%20blob%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Fsql-database-auditing%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20auditing%20%3C%2FA%3E%20on%20Azure%20SQL%20Server%20or%20Database%2C%20after%20you%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fsql-database%2Fsql-database-export%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20export%20%3C%2FA%3E%20database%20to%20.bacpac%20file%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20if%20you%20import%20the%20database%20to%20another%20Azure%20SQL%20DB%20that%20already%20have%20blob%20auditing%20enabled%20at%20the%20server%20level%20you%20may%20get%20this%20error%20message%3A%20%3CBR%20%2F%3E%3CP%3ECould%20not%20import%20package.%20%3CBR%20%2F%3E%20Error%20SQL72014%3A%20.Net%20SqlClient%20Data%20Provider%3A%20Msg%2015578%2C%20Level%2016%2C%20State%201%2C%20Line%201%20There%20is%20already%20a%20master%20key%20in%20the%20database.%20Please%20drop%20it%20before%20performing%20this%20statement.%20%3CBR%20%2F%3E%20Error%20SQL72045%3A%20Script%20execution%20error.%20The%20executed%20script%3A%20CREATE%20MASTER%20KEY%3B%3C%2FP%3E%3CBR%20%2F%3E%20if%20you%20import%20the%20database%20to%20local%20on-premise%20SQL%20Server%20installation%20you%20may%20get%20this%20error%3A%20%3CBR%20%2F%3E%3CP%3EError%20SQL72014%3A%20.Net%20SqlClient%20Data%20Provider%3A%20Msg%2033161%2C%20Level%2015%2C%20State%201%2C%20Line%201%20Database%20master%20keys%20without%20password%20are%20not%20supported%20in%20this%20version%20of%20SQL%20Server.%20%3CBR%20%2F%3E%20Error%20SQL72045%3A%20Script%20execution%20error.%20The%20executed%20script%3A%20%3CBR%20%2F%3E%20CREATE%20MASTER%20KEY%3B%3C%2FP%3E%3CBR%20%2F%3E%20this%20also%20apply%20if%20you%20created%20master%20key%20without%20password%20for%20your%20own%20usage.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3ECause%3A%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20This%20caused%20by%20a%26nbsp%3Bdifferent%20behavior%20between%20Azure%20SQL%20DB%20and%20Local%20SQL%20Server%20installation%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20a%20master%20key%20without%20password%20is%20an%20Azure%20SQL%20DB%20only%20feature%2C%20while%20local%20SQL%20Server%20installation%20must%20have%20password%20encryption%20for%20master%20key.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20read%20more%20about%20it%20here%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fsql%2Ft-sql%2Fstatements%2Fcreate-master-key-transact-sql%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20CREATE%20MASTER%20KEY%20(Transact-SQL)%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20failure%20to%20import%20back%20to%20Azure%20SQL%20caused%20by%20a%20limitation%20in%20the%20import%20process.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20our%20teams%20are%20currently%20working%20to%20change%26nbsp%3Bthis%20behavior%20from%20the%20server%20side.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3EResolution%3A%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CEM%3E%20Option%201%20%3C%2FEM%3E%20%3CBR%20%2F%3E%20to%20mitigate%20import%20to%20Azure%20SQL%20DB%20use%20the%26nbsp%3Bimport%20from%20the%20Azure%20portal.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20to%20mitigate%20import%20to%20local%20SQL%20Server%20installation%20you%20can%20alter%20the%20existing%20master%20key%20and%20add%20password%20encryption%20to%20it.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20this%20should%20be%20done%20before%20you%20export%20the%20database%20%3CBR%20%2F%3E%3CBLOCKQUOTE%3E%3CBR%20%2F%3E%20ALTER%20MASTER%20KEY%20ADD%20ENCRYPTION%20BY%20PASSWORD%20%3D%20'%3CPASSWORDHERE%3E'%3B%20%3CBR%20%2F%3E%3C%2FPASSWORDHERE%3E%3C%2FBLOCKQUOTE%3E%3CBR%20%2F%3E%20Option%202%20%3CBR%20%2F%3E%20for%20short%20term%20mitigation%20we%20provide%20you%20PowerShell%20script%20that%20do%20the%20following%3A%20%3CBR%20%2F%3E%3CUL%3E%3CBR%20%2F%3E%3CLI%3Eremove%20the%20master%20key%20object%20from%20the%20bacpac%3C%2FLI%3E%3CBR%20%2F%3E%3CLI%3Eremove%20the%20credential%20object%20from%20the%20bacpac%3C%2FLI%3E%3CBR%20%2F%3E%3C%2FUL%3E%3CBR%20%2F%3E%20after%20running%20this%20PS%20script%20on%20the%20bacpac%20you%20will%20have%20new%20bacpac%20file%20with%20%22patched%22%20suffix.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3E%20Download%20the%20PS%20script%20to%20fix%3A%20(updated%3A%202018-01-18)%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EBacpac%20larger%20than%204GB%20-%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fyochananrachamim%2FAzureSQL%2Fblob%2Fmaster%2FMasterKeyIssue%2FRemoveMasterKeyGT4GB.ps1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20here%3C%2FA%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EBacpac%20smaller%20than%204GB%20-%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fyochananrachamim%2FAzureSQL%2Fblob%2Fmaster%2FMasterKeyIssue%2FRemoveMasterKeyLT4GB.ps1%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20here%3C%2FA%3E%3C%2FP%3E%3CBR%20%2F%3E%20example%3A%20%3CBR%20%2F%3E%3CBLOCKQUOTE%3E%3CBR%20%2F%3E%20C%3A%5CPS%26gt%3B%20.%5CRemoveMasterKey.ps1%20%26nbsp%3B-bacpacPath%20%22C%3A%5CBacPacs%5CTest.bacpac%22%20%3CBR%20%2F%3E%3C%2FBLOCKQUOTE%3E%3CBR%20%2F%3E%20Option%203%20(Added%202017-09-11%20Clive%20Challinor%20%5BMSFT%5D)%20%3CBR%20%2F%3E%20I%20know%20there%20have%20been%20some%20issues%20with%20option%202%20above%2C%20so%20I%20thought%20I%E2%80%99d%20provide%20some%20additional%20detail%20on%20how%20to%20manually%20make%20the%20changes.%20If%20you%20do%20get%20problems%20with%20option%202%20and%20get%20the%20reported%20corrupt%20file%20message%20please%20raise%20a%20support%20call%20so%20we%20can%20have%20a%20look%20at%20a%20repro%20of%20the%20issue.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20I%E2%80%99d%20recommend%20that%20you%20first%20take%20a%20look%20at%20my%20article%20on%20how%20to%20edit%20a%20.bacpac%20file%2C%20you%20are%20going%20to%20need%20it!%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Fazuresqldbsupport%2F2017%2F08%2F16%2Fediting-a-bacpac-file%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Editing%20a%20.bacpac%20file%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20As%20a%20test%20I%20created%20a%20database%20and%20enabled%20auditing%2C%20and%20very%20little%20else%2C%20the%20unzipped%20model.xml%20looks%20something%20like%20this%20%3A%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CDATASCHEMAMODEL%20fileformatversion%3D%22%26quot%3B1.2%26quot%3B%22%20schemaversion%3D%22%26quot%3B3.0%26quot%3B%22%20dspname%3D%22%26quot%3BMicrosoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider%26quot%3B%22%20collationlcid%3D%22%26quot%3B1033%26quot%3B%22%20collationcasesensitive%3D%22%26quot%3BFalse%26quot%3B%22%20xmlns%3D%22%26quot%3B%26lt%3BA%22%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fsqlserver%2Fdac%2FSerialization%2F2012%2F02%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fsqlserver%2Fdac%2FSerialization%2F2012%2F02%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fsqlserver%2Fdac%2FSerialization%2F2012%2F02%3C%2FA%3E%22%26gt%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CMODEL%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CELEMENT%20type%3D%22%26quot%3BSqlDatabaseOptions%26quot%3B%22%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BCollation%26quot%3B%22%20value%3D%22%26quot%3BSQL_Latin1_General_CP1_CI_AS%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsAnsiPaddingOn%26quot%3B%22%20value%3D%22%26quot%3BFalse%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsQuotedIdentifierOn%26quot%3B%22%20value%3D%22%26quot%3BFalse%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsCursorDefaultScopeGlobal%26quot%3B%22%20value%3D%22%26quot%3BTrue%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsTornPageProtectionOn%26quot%3B%22%20value%3D%22%26quot%3BFalse%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsFullTextEnabled%26quot%3B%22%20value%3D%22%26quot%3BTrue%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BServiceBrokerOption%26quot%3B%22%20value%3D%22%26quot%3B1%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsAllowSnapshotIsolation%26quot%3B%22%20value%3D%22%26quot%3BTrue%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsReadCommittedSnapshot%26quot%3B%22%20value%3D%22%26quot%3BTrue%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsEncryptionOn%26quot%3B%22%20value%3D%22%26quot%3BTrue%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BFileStreamDirectoryName%26quot%3B%22%20value%3D%22%26quot%3B%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BTargetRecoveryTimePeriod%26quot%3B%22%20value%3D%22%26quot%3B120%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CRELATIONSHIP%20name%3D%22%26quot%3BDefaultFilegroup%26quot%3B%22%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CENTRY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CREFERENCES%20externalsource%3D%22%26quot%3BBuiltIns%26quot%3B%22%20name%3D%22%26quot%3B%5BPRIMARY%5D%26quot%3B%22%3E%3C%2FREFERENCES%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3C%2FENTRY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3C%2FRELATIONSHIP%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3C%2FELEMENT%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CELEMENT%20type%3D%22%26quot%3BSqlMasterKey%26quot%3B%22%3E%3C%2FELEMENT%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3C%2FMODEL%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3C%2FDATASCHEMAMODEL%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20When%20I%20ran%20it%20through%20the%20steps%20in%20method%201%20I%20end%20up%20with%20a%20file%20which%20looks%20like%20this%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CDATASCHEMAMODEL%20fileformatversion%3D%22%26quot%3B1.2%26quot%3B%22%20schemaversion%3D%22%26quot%3B3.0%26quot%3B%22%20dspname%3D%22%26quot%3BMicrosoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider%26quot%3B%22%20collationlcid%3D%22%26quot%3B1033%26quot%3B%22%20collationcasesensitive%3D%22%26quot%3BFalse%26quot%3B%22%20xmlns%3D%22%26quot%3B%26lt%3BA%22%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fsqlserver%2Fdac%2FSerialization%2F2012%2F02%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%3CA%20href%3D%22http%3A%2F%2Fschemas.microsoft.com%2Fsqlserver%2Fdac%2FSerialization%2F2012%2F02%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttp%3A%2F%2Fschemas.microsoft.com%2Fsqlserver%2Fdac%2FSerialization%2F2012%2F02%3C%2FA%3E%22%26gt%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CMODEL%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CELEMENT%20type%3D%22%26quot%3BSqlDatabaseOptions%26quot%3B%22%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BCollation%26quot%3B%22%20value%3D%22%26quot%3BSQL_Latin1_General_CP1_CI_AS%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsAnsiPaddingOn%26quot%3B%22%20value%3D%22%26quot%3BFalse%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsQuotedIdentifierOn%26quot%3B%22%20value%3D%22%26quot%3BFalse%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsCursorDefaultScopeGlobal%26quot%3B%22%20value%3D%22%26quot%3BTrue%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsTornPageProtectionOn%26quot%3B%22%20value%3D%22%26quot%3BFalse%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsFullTextEnabled%26quot%3B%22%20value%3D%22%26quot%3BTrue%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BServiceBrokerOption%26quot%3B%22%20value%3D%22%26quot%3B1%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsAllowSnapshotIsolation%26quot%3B%22%20value%3D%22%26quot%3BTrue%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsReadCommittedSnapshot%26quot%3B%22%20value%3D%22%26quot%3BTrue%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIsEncryptionOn%26quot%3B%22%20value%3D%22%26quot%3BTrue%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BFileStreamDirectoryName%26quot%3B%22%20value%3D%22%26quot%3B%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BTargetRecoveryTimePeriod%26quot%3B%22%20value%3D%22%26quot%3B120%26quot%3B%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CRELATIONSHIP%20name%3D%22%26quot%3BDefaultFilegroup%26quot%3B%22%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CENTRY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CREFERENCES%20externalsource%3D%22%26quot%3BBuiltIns%26quot%3B%22%20name%3D%22%26quot%3B%5BPRIMARY%5D%26quot%3B%22%3E%3C%2FREFERENCES%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3C%2FENTRY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3C%2FRELATIONSHIP%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3C%2FELEMENT%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3C%2FMODEL%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3C%2FDATASCHEMAMODEL%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20You%20can%20see%20clearly%20that%20in%20the%20patched%20version%20the%20%3CELEMENT%20type%3D%22%26quot%3BSqlMasterKey%26quot%3B%22%3E%3C%2FELEMENT%3E%20is%20gone%2C%20this%20should%20allow%20the%20import%20to%20work%20without%20error.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20As%20a%20side%20note%2C%20the%20patching%20code%20does%20a%20little%20bit%20more%20than%20just%20removing%20this%20key%2C%20I%20found%20that%20it%20also%20removed%20database%20credentials%2C%20so%20elements%20that%20look%20like%20this%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CELEMENT%20type%3D%22%26quot%3BSqlDatabaseCredential%26quot%3B%22%20name%3D%22%26quot%3B%5B%26lt%3BA%22%20href%3D%22https%3A%2F%2Fcbtevents.blob.core.windows.net%2Fevent%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%3CA%20href%3D%22https%3A%2F%2Fcbtevents.blob.core.windows.net%2Fevent%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fcbtevents.blob.core.windows.net%2Fevent%3C%2FA%3E%5D%22%26gt%3B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CPROPERTY%20name%3D%22%26quot%3BIdentity%26quot%3B%22%20value%3D%22%26quot%3BSHARED%22%20access%3D%22%22%20signature%3D%22%22%3E%3C%2FPROPERTY%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3C%2FELEMENT%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Also%20got%20removed%2C%20I%20didn%E2%80%99t%20get%20round%20to%20testing%20if%20this%20was%20absolutely%20necessary.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-368871%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Mar%2030%2C%202017%20Update%3A%20(2018-01-30)%20-%20Resolved%26nbsp%3BDacFX%20version%2017.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-368871%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20SQL%20Database%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20SQL%20DB%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eblob%20auditing%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eexport%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eimport%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Emaster%20key%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft
First published on MSDN on Mar 30, 2017

Update: (2018-01-30) - Resolved


DacFX version 17.4.1 has been released, this version contains the fix for all of the behaviors related to the master key.


you can download it here


to confirm you are using the correct version, verify that the file version of SQLPackage.exe is at least 14.0.3917.1


and follow the instructions here: using sqlpackage to import or export azure sql db


alternatively you use SSMS 17.6 and above, you can download it here




Symptoms:

When using blob auditing on Azure SQL Server or Database, after you export database to .bacpac file

if you import the database to another Azure SQL DB that already have blob auditing enabled at the server level you may get this error message:

Could not import package.
Error SQL72014: .Net SqlClient Data Provider: Msg 15578, Level 16, State 1, Line 1 There is already a master key in the database. Please drop it before performing this statement.
Error SQL72045: Script execution error. The executed script:
CREATE MASTER KEY;


if you import the database to local on-premise SQL Server installation you may get this error:

Error SQL72014: .Net SqlClient Data Provider: Msg 33161, Level 15, State 1, Line 1 Database master keys without password are not supported in this version of SQL Server.
Error SQL72045: Script execution error. The executed script:
CREATE MASTER KEY;


this also apply if you created master key without password for your own usage.

Cause:

This caused by a different behavior between Azure SQL DB and Local SQL Server installation

a master key without password is an Azure SQL DB only feature, while local SQL Server installation must have password encryption for master key.

read more about it here CREATE MASTER KEY (Transact-SQL)

failure to import back to Azure SQL caused by a limitation in the import process.

our teams are currently working to change this behavior from the server side.

Resolution:
Option 1
to mitigate import to Azure SQL DB use the import from the Azure portal.

to mitigate import to local SQL Server installation you can alter the existing master key and add password encryption to it.

this should be done before you export the database

ALTER MASTER KEY ADD ENCRYPTION BY PASSWORD = '<PasswordHere>';

Option 2
for short term mitigation we provide you PowerShell script that do the following:

  • remove the master key object from the bacpac

  • remove the credential object from the bacpac


after running this PS script on the bacpac you will have new bacpac file with "patched" suffix.

Download the PS script to fix: (updated: 2018-01-18)

Bacpac larger than 4GB - here


Bacpac smaller than 4GB - here


example:

C:\PS> .\RemoveMasterKey.ps1  -bacpacPath "C:\BacPacs\Test.bacpac"

Option 3 (Added 2017-09-11 Clive Challinor [MSFT])
I know there have been some issues with option 2 above, so I thought I’d provide some additional detail on how to manually make the changes. If you do get problems with option 2 and get the reported corrupt file message please raise a support call so we can have a look at a repro of the issue.

I’d recommend that you first take a look at my article on how to edit a .bacpac file, you are going to need it!

Editing a .bacpac file

As a test I created a database and enabled auditing, and very little else, the unzipped model.xml looks something like this :

<?xml version="1.0" encoding="utf-8"?>

<DataSchemaModel FileFormatVersion="1.2" SchemaVersion="3.0" DspName="Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider" CollationLcid="1033" CollationCaseSensitive="False" xmlns="http://schemas.microsoft.com/sqlserver/dac/Serialization/2012/02">

<Model>

<Element Type="SqlDatabaseOptions">

<Property Name="Collation" Value="SQL_Latin1_General_CP1_CI_AS" />

<Property Name="IsAnsiPaddingOn" Value="False" />

<Property Name="IsQuotedIdentifierOn" Value="False" />

<Property Name="IsCursorDefaultScopeGlobal" Value="True" />

<Property Name="IsTornPageProtectionOn" Value="False" />

<Property Name="IsFullTextEnabled" Value="True" />

<Property Name="ServiceBrokerOption" Value="1" />

<Property Name="IsAllowSnapshotIsolation" Value="True" />

<Property Name="IsReadCommittedSnapshot" Value="True" />

<Property Name="IsEncryptionOn" Value="True" />

<Property Name="FileStreamDirectoryName" Value="" />

<Property Name="TargetRecoveryTimePeriod" Value="120" />

<Relationship Name="DefaultFilegroup">

<Entry>

<References ExternalSource="BuiltIns" Name="[PRIMARY]" />

</Entry>

</Relationship>

</Element>

<Element Type="SqlMasterKey" />

</Model>

</DataSchemaModel>



When I ran it through the steps in method 1 I end up with a file which looks like this

<?xml version="1.0" encoding="utf-8"?>

<DataSchemaModel FileFormatVersion="1.2" SchemaVersion="3.0" DspName="Microsoft.Data.Tools.Schema.Sql.SqlAzureV12DatabaseSchemaProvider" CollationLcid="1033" CollationCaseSensitive="False" xmlns="http://schemas.microsoft.com/sqlserver/dac/Serialization/2012/02">

<Model>

<Element Type="SqlDatabaseOptions">

<Property Name="Collation" Value="SQL_Latin1_General_CP1_CI_AS" />

<Property Name="IsAnsiPaddingOn" Value="False" />

<Property Name="IsQuotedIdentifierOn" Value="False" />

<Property Name="IsCursorDefaultScopeGlobal" Value="True" />

<Property Name="IsTornPageProtectionOn" Value="False" />

<Property Name="IsFullTextEnabled" Value="True" />

<Property Name="ServiceBrokerOption" Value="1" />

<Property Name="IsAllowSnapshotIsolation" Value="True" />

<Property Name="IsReadCommittedSnapshot" Value="True" />

<Property Name="IsEncryptionOn" Value="True" />

<Property Name="FileStreamDirectoryName" Value="" />

<Property Name="TargetRecoveryTimePeriod" Value="120" />

<Relationship Name="DefaultFilegroup">

<Entry>

<References ExternalSource="BuiltIns" Name="[PRIMARY]" />

</Entry>

</Relationship>

</Element>

</Model>

</DataSchemaModel>



You can see clearly that in the patched version the <Element Type="SqlMasterKey" /> is gone, this should allow the import to work without error.

As a side note, the patching code does a little bit more than just removing this key, I found that it also removed database credentials, so elements that look like this



<Element Type="SqlDatabaseCredential" Name="[https://cbtevents.blob.core.windows.net/event]">

<Property Name="Identity" Value="SHARED ACCESS SIGNATURE" />

</Element>

Also got removed, I didn’t get round to testing if this was absolutely necessary.