Goal:
This time, let’s look at a very basic setup and get a feel about how you can use a Hybrid Connection based on Azure Service Bus Relay to connect for example an Azure Web App to a local database.
Topology:
So how does the topology for this scenario look like? Again, we require some resources on the Azure side and a few on the on-prem side.
Azure:
- Web App
- Hybrid Connection
- Service Bus Namespace
On-prem:
- Hybrid Connection Manager
- SQL Server

Actions:
- Local Setup:
In the interest of speed and efficiency, just use a very basic Asp.net Application running locally on your machine and which is connected to a local SQL Server Express Instance. I used a sample for this app from a public repository.
For example, to check the functionality of the app, enter an item in the DB:

This can be then be seen in the local SQL Server Database, when you query the specific table:

2. Azure Setup:
In this part we want to create an Azure Web App, push the local app to the Azure Web App and have it connect to the same on-prem SQL DB
Create an Azure Web App from the Portal, for this example, just choose an ASP.Net app and make sure the App Service Plan is at least Basic. App Service Hybrid Connections are only available in Basic, Standard, Premium, and Isolated pricing SKUs.
Once your Web App got created, create a new hybrid connection in the Web Apps “Networking” Menu

Download the Hybrid Connection Manager Tool, copy and install it on the on-prem machine which will act as the local endpoint relaying the connection to Azure. This can be a separate machine, but in the interest of using as few resources as possible, as in my case, this can be installed directly on the SQL Server.

Switch back to the Azure Portal and configure the required Hybrid Connection settings. Click “Create new hybrid connection”.

Enter a host name which can be resolved by the on-prem Hybrid Connection machine, and the port for the connections (in this case TCP 1433) also create a Service Bus namespace.

Once the Azure Hybrid Connection is there, switch back to the on-prem Machine and open the Hybrid Connection Manager UI. Add a new connection.

Login to your Azure Subscription

After saving it, it should show “Connected”

Now the web app is connected to the on-prem SQL Server, but the app is still plain vanilla meaning it is just default.
That is why we want to publish the local web application we used before, to the new Azure App Service. We can do this in a variety of ways, but in this case it s useful to do it over Visual Studio. Just open your local app in VS 2019 and publish it like described here: https://docs.microsoft.com/en-us/visualstudio/deployment/quickstart-deploy-to-azure?view=vs-2019
After publishing your app, you can access an administration endpoinf for your app, called Kudu or SCM. To reach it , you just enter scm in your URL like this : https://<webappname>.scm.azurewebsites.net . Here, you can use the Debug Console – CMD to test the connection

Here, confirm that the Hybrid Connection is up and running by using tcpping towards your local endpoint:

Now it is time to point your new app to the local sql DB. To achieve this, use the same Kudu Endpoint,navigate the integrated File Structure, locate the web.config file and configure the DB connection string.


After the change is save the Web App will restart,. Now reload the site and make a new DB entry to test the connection:

And query the local DB on the on-prem SQL Server to see the new entry.

Mission Completed 🙂