asp.net-coreentity-framework-coreazure-web-app-serviceasp.net-core-webapiazure-hybrid-connections

Web API hosted on Azure doesn't return On-Premise Data after Get Request


  1. I created an ASP.NET Core Web API and deployed it in Azure as an App Service.
  2. I created a Hybrid Connection and installed the Hybrid Connection Manager on the On-Premise Database Server, set the Hybrid Connection Status to Connected (Successfully connected the App Service with On-Premise Db Server).
  3. When sending Get Request or accessing the Web API on the web browser or Postman

The Result I receive is:

500 - The request timed out. The web server failed to respond within the specified time.

When developing the Web API on my local machine it works smoothly and I could connect to the On-Premise through a VPN connection. I also added this piece of code

services.AddDbContext<RepositoryContext>(o => o.UseSqlServer(connectionString, sqlServerOptionsAction: sqlOptions =>
{
  sqlOptions.EnableRetryOnFailure(
     maxRetryCount: 5,
     maxRetryDelay: TimeSpan.FromSeconds(60),
     errorNumbersToAdd: null);
}));

Solution

  • Problem

    The Hybrid Connection's Endpoint/Host I made in Azure had a different name as the SQL server. I named the endpoint randomly instead of giving it the actual name/IP address.

    Additional info

    Even if you installed the Connection Manager on the Server and the Status is set to Connected, this doesn't mean that your App Service will communicate with the Database.

    Solution

    Create a new Hybrid Connection and set the Endpoint Host name with the actual name/IP address, where the Hybrid Connection Manager is installed.