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. (p

Satva Solutions 1 Reputation point
2023-02-21T14:46:47.3166667+00:00

We used azure sql database connection with Azure functions

In the azure resources, we are facing the below issue on the live environment. When we restart the resource it automatically resolved it, then after some time, this issue repeats.

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.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.)

User's image

Please advise any solutions for that.

Azure SQL Database
Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
700 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,409 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Bas Pruijn 956 Reputation points
    2023-02-21T16:14:30.87+00:00

    If a restart of the function app results in a working situations, the basic network set-up is correct. To me this sounds like a SNAT port exhaustion. If your function is opening a connection to the database, it requires a port on the host to make the connection. When there are no more ports to open, you can get this kind of strange behaviour.

    To check please do the following:

    • in your Azure portal, go to the function app
    • in the left column, click the 'Diagnose and solve problems'
    • then click 'availability and performance'
    • in the left column click 'SNAT port exhaustion'.

    Now you will see a graph. I expect your graph to show an increasing line. This would indicate your code opens more ports than it closes. If this is the case, you should fix your code.

    Depending on the language you use, the root cause might be hidden in some third party packages/libraries you use though.

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.