Azure Hybrid Connection SQL Connection stops working. Restart of Web App helps. Problem with EnableRetryOnFailure?


I have an Azure Time stamping Web App connecting to about 50 different customers On Premise SQL databases using Hybrid connection. The web app is an Asp.Net Core 2.2 based C# app using EF. The app has been working extremely well over 2 years without any errors, but the recent week the SQL connections has during two different times stopped working. They will start immediately after a restart of the web app. This is of course extremely bad for my customers who need 24/7 working. The Azure failure messages indicate a problem with opening a SQL connection, which comes over time and is resetted by a web restart.

When studying the SQL failures in Azure all gives the same error number 10013 in trying to open the connection:

System.Data.SqlClient.SqlException (0x80131904): 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: TCP Provider, error: 0 - An attempt was made to access a socket in a way forbidden by its access permissions. Error Number:10013,State:0,Class:20

When more carefully examining the failures, it turns out that the first failure starts with a lot of 64-number errors as below (5-8) after which the succeeding errors are of type 10013 for all connections.

System.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - The specified network name is no longer available. Error Number:64,State:0,Class:20

My thoughts are: could this be because of using EnableRetryOnFailure as an sqlOption, and for some reason this will congest all SqlOpen tries in case of a badly working single connection. Code used in the web app:

  DbContextOptions dbConnOptions = SqlServerDbContextOptionsExtensions
    .UseSqlServer(new DbContextOptionsBuilder(), dbConnectionString,
    sqlServerOptionsAction: sqlOptions =>
      maxRetryCount: 10,
      maxRetryDelay: TimeSpan.FromSeconds(30),
      errorNumbersToAdd: null);

Could this be the reason to my SQL connection problems and would it be better to just let remove the EnableRetryOnFailure code? Or could there be a completely other solution to the problem?

Bengt Bredenberg, Premisol Oy, Helsinki, Finland

asked on Stack Overflow Mar 22, 2021 by user2302851

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0