How do I connect Azure Website to SQL Server on Azure VM? RRS feed

  • Question

  • User-296654088 posted

    We have a virtual machine running on Azure which is our database server. I'm now creating a new ASP.NET MVC 5 website which will run on Azure as well. How do I get it to use a database hosted in that VM?

    I think it'll be a web.config update where I point the connection string to that VM but now sure what it will look like. I'd appreciate some pointers on that.

    Saturday, December 28, 2013 3:32 PM

All replies

  • User-296654088 posted

    The virtual machine is in a virtual network. I found this page which suggests I need to use the "Persisten Virtual Machine IP". On my Azure portal, I don't see a persisten VM IP. I see two IPs listed: Public Virtual IP Address (VIP) and Internal IP Address. I tried both to no avail.

    Any suggestions? Do I need to do anything on the SQL Server VM on Azure? Not sure how the SQL Server VM would know to accept requests coming in from a website hosted on Azure? I feel I need to tell the SQL Server VM to accept requests coming from the Azure website.

    I'd appreciate your suggestions on this. Thanks.

    Saturday, December 28, 2013 4:17 PM
  • User-801004448 posted

    Can you ping any IP of SQL server VM from website VM? That's the first step to check connection between the two VMs.

    I think you need to open SQL remote port on SQL server VM. Default port is 1433.

    It would be easer to configure MSSQL on custom port and open the custom port on Windows firewall.

    Thursday, January 2, 2014 8:19 PM
  • User-691245060 posted

    @SamU - 

    you have to add 1433 endpoint to the VM for SQL Connectivity. Open the same port in VM by adding a Firewall InBound Rule.

    Also you need to configure TCP/IP connections for SQL Instance.

    Then create SQL Authentication along with Windows Authentication.

    Ref - http://www.windowsazure.com/en-us/manage/windows/common-tasks/install-sql-server/


    Monday, January 6, 2014 4:57 AM
  • User-296654088 posted

    I did all of that.

    Since I posted this question, I found some questions posted on Stackoverflow with similar situations and some indicated that websites cannot connect to a virtual network. Is this true?

    My SQL Server VM is in a virtual network on Azure. I wonder if that's what's causing the issue.

    Monday, January 6, 2014 10:32 AM
  • User-691245060 posted

    if you are using AzureWebsites, then connecting to SQL on Virtual netowek couldnt be possible.

    If you are using Webroles, then join the webrole to the Virtual network. that is the only way.


    Tuesday, January 7, 2014 7:15 AM
  • User-856709386 posted

    It can.

    You just set IP address range in this link. Azure WebSites use one of them. http://blogs.technet.com/b/keithmayer/archive/2013/08/14/windows-azure-datacenter-ip-ranges.aspx#.UhOML5LFVy4

    I successfully connect to my MSSQL server on VM.

    Thursday, May 1, 2014 1:35 PM
  • User-1605061603 posted

    This is possible but you will have to create Point to Site Connections & Gateways and open up ports.  Test connectivity by using tcpping ip and port from the kudu console of your web app.  Once you get this ping to respond to your Virtual Ip assigned to your vm - you should be good to go here.

    Then you will have to modify your mvc app to get that information from environment variables.

    When you deploy to azure, your web connection string information is persisted to environment variables that you can reset from the azure portal.

    Move all connection strings information out of web and app config files into ignore files.  and exclude those files from source control - do not check in this info to source control.

    Then have a powershell post build step that adds the environment variables automatically for you in dev.  

    At this point you should be able to test your app for connectivity by checking the db and identifying your spid.

    Hope this helps,


    Wednesday, August 2, 2017 12:06 AM