"Could not import package" when restoring a Windows Azure SQL Database Export
One of my customers encountered some issues when trying to restore a Windows Azure SQL Database export:
If we take a closer look at the error for the Importing database operation we'll see the following:
Could not import package… ‘getnewrowversion' is not a recognized built-in function name.
According to the error message and a few posts on the MSDN forum this exception is caused due to the fact that Data Sync had previously been enabled on this database and the getnewrowversion function is not available when restoring the database. Since this function simply returns a BIGINT you can easily replace it with a zero.
A bacpac file is actually a Package (you'll find that class in the System.IO.Packaging namespace), so you can open and edit the file using managed code. That's why I created a simple console application that:
- Replaces all calls to getnewrowversion() to 0 (zero) in the model.xml file
- Updates the checksum for the model.xml file in the Origin.xml file
The complete source for this application is available on GitHub: https://github.com/sandrinodimattia/WindowsAzure-SqlDatabaseExportFix. The binaries can be downloaded here.
The tool takes 1 parameter: the path to the *.bacpac file. If you run the tool it will go through the *.bacpac file, make the required changes and update the export. I suggest you take a backup of the export just to be sure.
After that you'll be able to import the BACPAC using the "Import Data-tier application" wizard: