Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to On Prem SQL server from Azure Web app

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

like image 916
umesh.chape Avatar asked Feb 22 '19 07:02

umesh.chape


People also ask

Can Azure App service connect to on-premises SQL Server?

Connect to on-premises SQL Server from a web app in Azure App Service using Hybrid Connections. Hybrid Connections can connect Azure App Service Web Apps to on-premises resources that use a static TCP port. Supported resources include Microsoft SQL Server, MySQL, HTTP Web APIs, Mobile Services, and most custom Web Services.

How do I connect SQL Server to Azure web app?

Publish the web application to an Azure Web App. Create an Azure Hybrid Connection using Azure Preview Portal. (New Portal). Complete the connection by installing a Listener Setup in an on-premise server (where SQL Server is installed). Access an on-premise database from the web app.

How to create a hybrid connection in Azure App service?

Navigate to App Service which we created in Step 4 in Azure, and navigate to Networking. Click on Hybrid Connections > Configure your Hybrid Endpoints Create New Hybrid Connection.

Why can't I login to SQL Server from Azure App service?

The login is from an untrusted domain and cannot be used with Windows authentication. " Please suggest how to use windows mode of authentication while forming connection string to the on-premises SQL Server from Azure App Service. Show activity on this post.


2 Answers

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.

like image 169
Nancy Xiong Avatar answered Sep 26 '22 05:09

Nancy Xiong


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.

like image 24
Mukesh Arora Avatar answered Sep 24 '22 05:09

Mukesh Arora