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

563 Views Asked by At
  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);
}));
2

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On

In the absence of more information, the 500 error, I guess the most likely reason is that there is a problem connecting to the On-Premise sql server.

TroubleShooting:

  1. Click Diagnose and solve problems to view Application Event Log to view specific logs.

    enter image description here

  2. (Optional) Open Application Logging (Filesystem) and Detailed error message.

    Specifically, you can log in to the scm website to view the error log.

    enter image description here

  3. If you test the interface and connect to the database locally or using vpn, there is definitely no problem. Now the problem must be the database connection part. It is recommended to recheck Hybrid connections. You also can raise a support ticket on portal, let them check logs and help you.

Related Posts:

1. Hybrid Connection Shows “Connected”, but Application Fails to Connect

2. Azure Web App Hybrid Connection Failing