0

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 =>
    {
      sqlOptions.EnableRetryOnFailure(
      maxRetryCount: 10,
      maxRetryDelay: TimeSpan.FromSeconds(30),
      errorNumbersToAdd: null);
    }).Options;

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

BengtBr
  • 11
  • 2
  • Hi @user2302851 , I am facing the same issue. After restarting the app service from Azure portal, it works fine again. Facing this issue continuously after some days. Did you find any solution for this? – Rahul Sep 15 '21 at 18:34
  • What I did then in March was to replace the command above with the following DbContextOptions dbConnOptions = SqlServerDbContextOptionsExtensions.UseSqlServer (new DbContextOptionsBuilder(), esmikkoConnectionString).Options; i.e removing the RetryOnFailure part and sofar the same type of error has not occured. Some other errors stopping the web app has also occured, so I have also made the following changes to the web app. - Removed all extra loggings in Web.config (stdoutLogEnabled="false") - Restart the WebApp automatically once a week on Sunday night at 3:00 AM – BengtBr Oct 05 '21 at 14:11

0 Answers0