This is my Azure configuration:
- I have a Virtual Network with a couple of subnets and a gateway configured to allow point-to-site.
- There is one Virtual Machine with SQL Server (2014) installed. There are some databases in there already. SQL Server is set up to allow SQL Server and Windows Authentication mode. This VM is in the Virtual Network
- I have an empty Azure Web App
I deployed my main MVC WebApp to the empty Azure Web App and looks good, except when it tries to retrieve information from the database.
Is it a connection string error? or there can be something else...
My connection string looks like this:
<add name="MyEntities" connectionString="metadata=res://*/Data.MyModel.csdl| res://*/Data.MyModel.ssdl| res://*/Data.MyModel.msl;provider=System.Data.SqlClient;
provider connection string="
persist security info=False;
Here is the error thrown by the azure web app...
So it seems to be related to either the way I'm providing the connection string or the end-points/firewall configuration.
Best How To :
The other answers gave me the guidelines to find out the solution.
I'll try to describe the steps I followed:
- Using the new azure portal (portal.azure.com currently in preview) I established a connection between the Azure Web App and the Virtual network:
- Home > Browse > Click on Azure Web App name
- In the Azure Web App blade click on Networking tile
- In Virtual Network blade, click on the Virtual Network where the database is located (it's important to mention that the Virtual Network ought to have a gateway previously configured)
My intention was to provide certain level of security to the VM with the databases by placing it inside a Virtual Network, so I had not considered opening ports. Turns out that it's necessary, so, in the VM:
I enabled the TCP/IP protocol for SQL Server using the Sql Server Configuration Manager (How to? here)
Then I created a new Inbound Rule opening the 1433 port, but only for private connections (very nice).
- It was not necessary to create an endpoint in the VM for this port (very happy with this).
- Finally, I published the the app to the Azure Web App using the connection strings as shown in the question (with internal database IP)
Final touch: in the new Azure Portal > Azure Web App > Settings, I was able to enter Connection Strings. Settings created in the portal are not overwritten; so now I'm sure this Azure Web App will always use the correct connection string.
Final note: in theory (not tested yet) the internal IP will not change as long as the VM is not Stopped (Deallocated).