12

I have .Net application at on prim. I want to host it at Azure but don't want to move database. I publish the application on Azure but it is not able to connect to on prim database.

SQL server is in private netwrok.

For POC purpose, I am using MSDN subscription. I am facing below error,

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Thanks, Umesh

umesh.chape
  • 2,895
  • 5
  • 16
  • 17
  • 1
    Please refer to this answer: https://stackoverflow.com/questions/49898320/azure-hybrid-connection-not-working/49899686#49899686 – Tayyab Feb 26 '19 at 08:01
  • Hopefully it would be helpful as it covers most of the problem and details related to the Hybrid Connection. – Tayyab Feb 26 '19 at 08:02

2 Answers2

24

Since your on-premise database is in your private on-premise network, Azure service could not find it, you could expose a public IP for the on-premise database or use Azure web app service VNet integration with Azure VPN gateway to securely access the resource in an Azure VNet or on-premise network.

Another recommended method is to use an Azure App Service Hybrid Connections. To do this, you need to add and create Hybrid Connections in your app. You will download and install an agent (the Hybrid Connection Manager) in the database server or another server which is in the same network as the on-premise database.

The main steps are as follows:

  1. You configure a logical connection on your app service or web app.
  2. A small agent, the Hybrid Connection Manager, is downloaded and installed on a Windows Server (2012 or later) running in the remote network (on-premises or anywhere) that you need to communicate with.
  3. You log into your Azure subscription in the Hybrid Connection manager and select the logical connection in your app service.
  4. The Hybrid Connection Manager will initiate a secure tunnel out (TCP 80/443) to your app service in Azure.
  5. Your app service can now communicate with TCP-based services, on Windows or Linux, in the remote network via the Hybrid Connection Manager.

You could get more details on how to Connect Azure Web Apps To On-Premises.

Nancy
  • 26,865
  • 3
  • 18
  • 34
  • 1
    Thanks Nancy. I have created Azure App Service Hybrid Connections but facing same issue. I have done Hybrid Connections with below steps, 1. Created hybrid connection with details like endpoint host, endpoint port 2. Hybrid Connection Manager installed on one server and database server is on different server. 3. Endpoint Host: IP address of server where Hybrid Connection Manager installed 4. Endpoint Post: 443 Please help me if I am missing anything Thanks – umesh.chape Feb 22 '19 at 09:16
  • For SQL connection, you could specify the endpoint port 1433 and database host as the endpoint host following [this](https://learn.microsoft.com/en-us/azure/app-service/app-service-hybrid-connections#add-and-create-hybrid-connections-in-your-app) Also, check [these steps](https://success.scribesoft.com/s/article/Named-Pipes-Provider-Error-40) on your side. – Nancy Feb 22 '19 at 10:17
  • 1
    In my case database server and Hybrid Connection Manager are different hence I have mentioned endpoint host as Hybrid Connection Manager server and port number 80/443. I have mentioned that I am using MSDN subscription and not sure if issue is due to that? – umesh.chape Feb 22 '19 at 11:48
  • Have a wrong configure with the hybrid connection. please use endpoint port: the default port 1433 for SQL server and endpoint hostname: a computer name of your SQL server host computer. Make sure the hybrid connection status is connected and download the HCM agent. Install it and create another hybrid connection in the UI of HCM, Type the Azure portal credential. Refresh the page and make sure the hybrid connection is connected. Refer to this [blog](https://blogs.msdn.microsoft.com/waws/2017/05/22/hybrid-connection-shows-connected-but-application-fails-to-connect/). – Nancy Feb 25 '19 at 07:53
  • 1
    My sql server's OS is not upgraded so I don't think I can install and use HCM from SQL server. anyway thanks for your suggestion. – umesh.chape Feb 25 '19 at 08:44
  • 2
    You could install the HCM in another server instead of sql server and configure the hybrid connection endpoint host--database hostname, endpoint port--- 1433 from azure app service. You could go through these links [here](https://learn.microsoft.com/en-us/azure/app-service/app-service-hybrid-connections#add-and-create-hybrid-connections-in-your-app) and [here](https://blogs.msdn.microsoft.com/waws/2017/05/22/hybrid-connection-shows-connected-but-application-fails-to-connect/) as I mentioned before. – Nancy Feb 26 '19 at 08:00
  • @NancyXiong, Since I am using ExpressRoute, would it be possible to access the OnPremise SQL Database from the App Service? – Senior Systems Engineer Nov 17 '20 at 12:36
  • 1
    @SeniorSystemsEngineer it's possible, see [this](https://learn.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet#regional-vnet-integration) regional VNet Integration enables your app to access resources across Azure ExpressRoute connections – Nancy Nov 18 '20 at 02:53
3

Your on-premise SQL server must be hosted on public IP Address to connect from Azure Web APP. Once you will expose your SQL server on public IP, you should also apply firewall rules to ensure that only Azure Web App can access for security perspective.

Mukesh Arora
  • 1,763
  • 2
  • 8
  • 19