Blog Post

Microsoft Developer Community Blog
2 MIN READ

SQL Azure Tip! - Failures importing Bacpac

chilberto's avatar
chilberto
Iron Contributor
Feb 12, 2019

First published on MSDN on Sep 25, 2016

Authored by Jeffrey Chilberto

 


Most of the time importing bacpac files from SQL Azure locally works without an issue but occassionally there will be an issue when a particular setting has been used that is not supported in the destination database version.  There are many forum and stack overflow posts in regards to these sneaky little issues so here is a tip when working with bacpacs.  They're zips...

Recently I had a requirement to bring a SQL Azure database down to my local SQL server and ran into a compatibility issue:

Error SQL72014: .Net SqlClient Data Provider: Msg 4631, Level 16, State 1, Line 1 The permission 'ALTER ANY DATABASE EVENT SESSION' is not supported in this version of SQL Server.


I was not able to alter the SQL Azure database in order to alter or remove any security settings so I was forced to take a different approach... in other words, I had to hack the bacpac.

    1. Make a copy of the bacpac...

 

    1. Rename the copy by changing the extension to .zip

 

    1. Open the zip and open the model.xml file

 

    1. In my situation I found the element containing the ALTER ANY DATABASE EVENT SESSION command and I deleted it.

 

    1. Rename the zip back to bacpac

 

    1. The bacpac does contain a checksum that it uses to validate the package.  This needs to be updated.  Fortuntately there is a git copy of the dacchksum.exe utility.  Simply run against the new bacpac in order to get the checksum value.

 

    1. Rename the bacpac back to zip

 

    1. Inside the zip, open the origin.xml and update the checksum

 

    1. Rename the zip back to bacpac

 

    1. Try the import again!



Note: In four years I have only had to resort to this twice so I do view this as a last resort.

SQL Azure Backup References

 



Cheers!

Updated Mar 28, 2020
Version 3.0

2 Comments

  • Sylvain_Roy's avatar
    Sylvain_Roy
    Copper Contributor

    The model.xml file has changed format and there is now an XML node starting at <Element Type="SqlPermissionStatement" Name="[Grant.AlterAnyDatabaseEventSession.Database].[an SQL login name].[dbo]">

     

    However, deleting this node corrupts the package. I thought it was because the number of permission in the origin.xml file was incorrect, but even after changing it. The SQL import always report that package contains corrupt data.

     

    Maybe someone will eventually find a solution for this... in the meantime, it looks like you cannot bring an SQL Azure database with such properties/permissions in an on-premise instance.

  • Sylvain_Roy's avatar
    Sylvain_Roy
    Copper Contributor

    Just got this same error on a Dynamics Business Central database BACPAC, but didn't find the string in any of the .zip file... would you have any other ideas?