Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy database to Azure SQL fails, sp_MSforeachtable not found

I am trying to publish a SQL Server database using a .dacpac and publish profile to an Azure SQL database. We have been using on premises SQL Server with no problems for quite some time, and now we are evaluating Azure and AWS to see which is best suited for our needs.

We have a SQL Server database project and want to deploy it to Azure SQL database, however it fails to execute the script generated by SSDT. This is because the generated script contains a call to the stored procedure sp_MSforeachtable which does not exist in Azure SQL.

I also have changed the target platform from SQL Server 2016 to Azure SQL V12. I am trying this from Visual Studio 2017's publish profile and from VSTS Release management using Azure SQL database deployment task. An of course by providing the necessary .dacpac and publish.xml files in the task.

I know I can manually add the stored procedure, however it doesn't seem that is what is intended by these publishing/deployment methods. Does anyone have any ideas?

Thanks

like image 757
dotnetmensch Avatar asked Oct 09 '17 17:10

dotnetmensch


People also ask

What is sp_MSforeachtable?

sp_MSforeachtable is a stored procedure that is mostly used to apply a T-SQL command to every table, iteratively, that exists in the current database.

How do I import a Dacpac file to Azure SQL?

To import from a BACPAC file into a new single database using the Azure portal, open the appropriate server page and then, on the toolbar, select Import database. Select the storage account and the container for the BACPAC file and then select the BACPAC file from which to import.

How do I enable Port 1433 on Azure?

By default, access through the Azure SQL Database firewall is disabled for all Azure services. Choose ON on this page to enable access for all Azure services. Select Save. Port 1433 is now open on the server and a server-level IP-based, firewall rule is created for your current IP address.


2 Answers

This feature is not implemented in SQL Database in Azure.

You can find a copy of it at this location: https://gist.github.com/metaskills/893599

like image 91
Fredrik Avatar answered Sep 21 '22 06:09

Fredrik


sp_MSforeachtable is an undocumented stored procedure in the Master database. This apparently hasn't been ported over to Azure SQL. I believe you'll need to add it manually to the Master database. Once that is done, your DACPAC should work just fine on your own Azure SQL database. I don't see a problem with manually adding sp_MSforeachtable. DACPACs are meant to keep your database in sync, not the Master database.

like image 43
Rob Reagan Avatar answered Sep 18 '22 06:09

Rob Reagan