A network-related or instance-specific error occurred while establishing a connection to SQL Server.

Hoàng Lê Hiệp Minh 51 Reputation points
2023-03-16T10:58:04.21+00:00

I have 3 Resources Group Environments with the names Dev01, Dev02, and Dev03. Each Resources Group have 4 App Service Plan and all of them are located in 1 App Service Environment. SQL Server located on Dev01. Web App Dev02 and Dev03 will call to SQL Server on Dev01.

The issue happened on Dev03 ENV, when I use the web app on Dev03 it's working as well but issues start when Function app connects to SQL.

  1. I had open Kudu run cmd tpcping aaaaaaaa.database.windows.net,1433 it's still working not time out.
  2. I tried to check on Dev02 at that time it's still ok no issue.
  3. I compared infrastructure Dev02 & Dev03 and didn't see differences between them because they use the same App Service Environment.
  4. I restart Function App but does not work.
  5. All Web Apps use Managed Identity connect to SQL so I don't think issue is from authen because Web Apps Dev03 can connect and write data in SQL

Anyone has been faced with that issue, I have no idea about this case please help me.

Thanks a lot!

System.AggregateException: One or more errors occurred. (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: HTTP Provider, error: 0 - ))
 ---> Microsoft.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: HTTP Provider, error: 0 - )
   at Microsoft.Data.ProviderBase.DbConnectionPool.CheckPoolBlockingPeriod(Exception e)
   at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen()
--- End of stack trace from previous location ---
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.SplitQueryingEnumerable`1.AsyncEnumerator.InitializeReaderAsync(AsyncEnumerator enumerator, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.ExecutionStrategy.<>c__DisplayClass33_0`2.<
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,323 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,791 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Hoàng Lê Hiệp Minh 51 Reputation points
    2023-03-18T10:47:32.13+00:00

    After took many times compared in Kudu I saw the abnormal folder Runtimes in D:\home\site\wwwroot\bin. I deleted the folder and restarted Function App and tried again, it has worked as well.16

    1 person found this answer helpful.

  2. CosmogHong-MSFT 23,321 Reputation points Microsoft Vendor
    2023-03-17T02:50:00.55+00:00

    Hi @Hoàng Lê Hiệp Minh

    Try troubleshooting follow by this document: A network-related or instance-specific error occurred while establishing a connection to SQL Server.

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.