theRonny
theRonny

Reputation: 395

Publishing a MVC App in Azure Web App

This is my Azure configuration:

  1. I have a Virtual Network with a couple of subnets and a gateway configured to allow point-to-site.
  2. 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
  3. 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=&quot;
                                                                                                                        data source=tcp:10.0.1.4;
                                                                                                                        initial catalog=MyDataBase;
                                                                                                                        persist security info=False;
                                                                                                                        user id=MySystemAdmin;
                                                                                                                        password=SystemAdminPassword;
                                                                                                                        multipleactiveresultsets=True;
                                                                                                                        App=EntityFramework&quot;" 
                                                                providerName="System.Data.EntityClient" />

Here is the error thrown by the azure web app...

enter image description here

So it seems to be related to either the way I'm providing the connection string or the end-points/firewall configuration.

Upvotes: 2

Views: 115

Answers (3)

theRonny
theRonny

Reputation: 395

The other answers gave me the guidelines to find out the solution.

I'll try to describe the steps I followed:

  1. 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)
  2. 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).
  3. 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).

Upvotes: 0

Panos
Panos

Reputation: 1973

What the guys said above plus:

  1. The Web App needs to have a hybrid connection to the VNET the VM is if you want to use the local IP address, otherwise you have to use the PIP.
  2. Check the firewall on the VM if the proper ports are open. This has to be both on the VM firewall and the endpoints. Also, if there are any ACLs on the VM, you have to check those too.

Upvotes: 1

Bil Simser
Bil Simser

Reputation: 1723

Check your connection string against this connection string for Entity Framework designer files (https://msdn.microsoft.com/en-us/data/jj556606.aspx#Connection)

Just from a quick glance I see two possible errors:

  1. Semicolon missing added after provider=System.Data.SqlClient (the example on the page I provided the link to doesn't have one)
  2. The IP address you specify to connect to is a local one (10.0.0.1) and should be the IP/DNS name of your database in Azure.

Not sure if this is the issue or if StackOverflow just clobbered your markup. In addition you talk about a lot of gateways so I would check to make sure you can talk between your systems. Finally posting error messages and capturing exceptions about what's actually going on will help diagnose the error because at this point it's all guesswork.

Hope that helps.

Upvotes: 3

Related Questions