Azure Function VNet integration breaks randomly - azure

I'm using Azure Functions with .NET 6 on an S1-tier App Service Plan with regional VNET integration. In our scenario, we execute some SQL queries accessing an On-Prem database which works pretty fine at the first glance. Unfortunately, sometimes the virtual network connection seems to break and our queries run into following error:
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.) An attempt was made to access a socket in a way forbidden by its access permissions.
After disconnecting and reconnecting the function from VNET, it starts working again as expected (I found this approach here)
But it seems like this is just a really poor workaround. Does anybody know how to fix this indefinitely? I've already tried creating a new function app but that didn't change anything.

• According to the error that you are encountering, there might be some issues with the Firewall in the on-premises environment or the TCP/IP connection being established. Thus, I would suggest you to please check all the issues mentioned in the documentation link below and verify whether all the instances of practices mentioned in it are followed correctly: -
https://learn.microsoft.com/en-us/troubleshoot/sql/connect/network-related-or-instance-specific-error-occurred-while-establishing-connection
• Secondly, I would suggest you to please check the SQL Browser Service in the on-premises SQL Database server and check whether ‘UDP port 1434’ is whitelisted for communication between the two environments or not along with TCP 1434. Also, when executing SQL queries to access the on-premises SQL DB, ensure that the instance name is input correctly along with the port number. Also, when mentioning the port number, ensure that it is preceded by ‘,’ and not ‘:’.
• Finally, I would suggest you enable diagnostic logging for an app service plan by referring to the below documentation link that will help you figure out the reason for your connection error to the SQL DB. Also, you can browse through the Kudu console by accessing the url:- https://****.scm.azurewebsites.net/ (enter your website name instead of ****). You should be able to find the log files under the debug console. Please check if there are any failure logs: -
https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs#:~:text=To%20enable%20application%20logging%20for,itself%20off%20in%2012%20hours.
https://github.com/projectkudu/kudu/wiki/Investigating-issues
Note: - Please check whether your API URL connection string used in the function app is being replaced correctly and troubleshoot your connection variables thoroughly.

Related

Connect Azure App Service and Azure SQL VM

I have a setup where the connection string of my .NET application is configured at the app service level and the database used in it is present in an Azure SQL VM
I see the following error, while accessing my Web APIs in the app service
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 - Access is denied.
However, I’m able to connect to the database directly on my local system using SSMS with my organisation’s VPN
I’m struggling to find the right resource, appreciate if you someone can help me with steps to fix it
i just have the beginner level knowledge on Azure platform
I tried to reproduce the same in my environment I got the same error like below.
To resolve this issue i have removed private access and tried and then added new private access its work successfully.
Check the public access in selected network with firewall rule and allow exception as below.
And, when I remove this private endpoint and try to add new private access i can able to connect with my sql server.
Check this connectivity as below.
My azuresql,database server connected successfully.
Note: This error may occur in multiple ways if are not enable sql services and in tcp/Ip If any of the protocols are disabled or if Remote Connection Permission is disable error may occur for this please refer the below documents.
Reference:
Microsoft SQL Server Error 2 Cannot Connect to Local: How to Solve? (systoolsgroup.com)
Resolving could not open a connection to SQL Server errors (mssqltips.com)

Can't connect to new Azure SQL Server instance

I've just spun up an instance Azure SQL server. I can connect to it from the Azure Portal, but I get a timeout error when trying to connect with SQL Management Studio (and other methods):
Cannot connect to *server*,*port*.
Additional information:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.)
(Microsoft SQL Server, Error: 121)
The semaphore timeout period has expired
I've been searching for a solution but the only thing I find about the error message is that the database is under heavy load, which seems unlikely concidering it was just created!
Anybody know what can cause this problem?
Thanks!
Error 121 has always been considered a network related error as you can read in this Microsoft Support article. The Internet service you receive, network adapters are things you should consider examine.
Please consider to click the "Options" button of SQL Server Management Studio, on the "Connection Properties" tab, try setting a greater value for the "Connection time-out" setting.
If you need to use a Corporate VPN to connect to Azure SQL Database, make sure you are connected to the VPN.
Problem is related to a Firewall in the middle doing SSL inspection.
I Suggest to try requesting your firewall admin to add an exemption on the SSL Inspection engine , or try using another connection not doing SSL inspection.
So it seems it was the company firewall that was blocking the traffic. I tried from another network entirely and then I could access the server.
I guess my two alternatives now are either to unblock 1433 in the company firewall, or to open another port in Azure SQL Server, which doesn't seem possible at the moment.

Getting an intermittent error while connecting to on-premise sql database from Azure service

Created an azure MVC website, from service (controller) code we are connecting to an on-premise sql server using Azure Hybrid Connection. Intermittently we are facing below issue.
"A transport-level error has occurred when receiving results from the
server. (provider: TCP Provider, error: 0 - The specified network name
is no longer available.)"
Please provide suggestions to resolve this issue.
You can try following solutions :
Try increasing connection time-out.
check if remote connection is enabled.
Try adding firewall exception.
First of all the error means either the networks has some extra latency, the database is down or you may have too many concurrent connections open the database.
(Make sure you are closing all open datareaders.)
also it may be due to this
These are transient faults and are to be expected in the cloud. Implementing defensive programming is usually a must in the cloud. Try using some retry logic. Microsoft's transient fault exception library is an excellent start. Though meant primarily for SQL Azure and Azure Service bus, you can use the library for SQL IaaS.
In my opinion, 98% sure, because I recently had the same experience, it is a network issue from the server provider.
For instance: if you are rent the server from Ionos, by default all remote connections are blocked, even though you disable the firewall in the server. You still won't be able to connect remotely. You can, however, do your work on the server without any problem.
To connect remotely, you have to contact the server provider. They will explain how to enable firewall ports from your control panel.
I contacted my server provider as I almost get frustrated. Here was their response.
enter image description here
After this, every permitted client can connect remotely to the server.
I wish you success.

Cant connect to Azure DB from Azure web application

I am trying to set up a new azure website. I have done this before and everything just worked, this time I'm having real trouble getting the database set up.
I setup both site and database in the deploy wizard, and have a connection string named the same as on my local box. The error I'm getting is below:
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: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)
If i copy paste the connection string from azure to my local box (and add my local ip to the whitelist for SqlAzure) then it works fine locally (which is why I'm a little stumped)
The only thing that that I have noticed is that if I download the web.config for the site as configured in azure there are no connection strings. I imagine that this is because they are doing some clever security thing.
Any idea what I can even try next to diagnose this?

Sharepoint application not working!

I am facing a weird problem and no body seems to have a solution for it.
The thing is that i am working on a Sharepoint application. It was working fine until our organization underwent a network maintenance.
The next day i try to run my application and kaboom!! it throws me an error
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: Named Pipes
Provider, error: 40 - Could not open a
connection to SQL Server)
I later found out that during the maintenance the IP of my machine has changed.
It is possible that the change of an IP could result in my sharepoint application not working!!
I did my research and found that nothing has been changed in my application and that the SQL server (which is on my machine itself) is working fine! And still my application is DEAD!!
Please help, any suggestions will be helpful!
thank you.
DON'T PANIC!
The error message is pretty clear and it's not related to Sharepoint. Your web application can no longer connect to the database.
Perhaps you have configured Windows Firewall (or another firewall) to allow connections to the database using your old IP. Maybe you haven't enabled Named Pipes or you have hard-coded the old IP address in your hosts file. Or maybe your web application's account can no longer connect to the database. Changing a server's IP is no small change so maybe someone did a few more modifications as well.
If you can connect to your Central Administration site the problem is probably related to the Web Application's account. If you can't connect to Central Admin, the problem is related to the database connection.
To check the connection try to connect to the database using the exact same credentials (Provider Name, account, password etc.). You can do this either by using the Options tab of the SQL Server Management Studio connection dialog, or by writing a small program yourself to test the connection to the database.

Resources