Cant connect to Azure DB from Azure web application - azure

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?

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)

Azure Function VNet integration breaks randomly

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.

Why do I get "A network-related or instance-specific error occurred while establishing a connection to SQL Server."?

I have developed a simple Web API and deployed it on an Azure server along with a SQL Server database. The database and the Web API are hosted on the same server. I can connect to the database from my development machine. If I run the Web API in Visual Studio 2017, everything works fine, I can call all Web methods and I get the proper expected response.
Now, that I deployed the Web API on the server and run it under IIS, if I make a Web API call using Postman I get this error message after about 30 seconds of wait time:
"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 know this error has been discussed here many times, but none of the suggestions made help solve my problem. The hosting Azure VM is a 64-bit Windows Server 2016.
In the connection string used by my Web API I had the data source set to the computer's name, its internal Ip address, the "localhost" keyword or the "127.0.0.1" back-loop IP address, but I get the same error listed above in each of those situations. SQL Server Management Studio (running locally on the same server that hosts the database and my Web API) is able to connect to the database if I use either of the three data sources: localhost, internal IP address or computer name.
In the situation in which it works, when I run the Web API in Visual Studio, the data source in the connection string is set to the external Ip address of the Azure Server. That would be the only difference, as far as the data source is concerned.
I need to mention that I have a couple of web methods that do not require database access. These work fine and return the expected result.
Are there other specific settings that I would need to do in IIS to allow this to happen?
TIA,
Eddie
I figured what the problem was. My Web API was developed in ASP.Net Core and as such, it produces its own executable. That is looking for a config file that is named TheNameOfTheApplication.exe.config.
Due to a temporary lapse of reason, I was modifying the connection string in the "app.config" file and left the one in the "TheNameOfTheApplication.exe.config" file with the external IP address that was not correct.

How to migrate a dockerized SQL Server database that uses a custom port to Azure SQL

I am hosting a bunch of micro-services and bot apps using Docker, and Azure virtual machines. There´s also a dockerized SQL Server 2017 instance in the stack, which I would like to migrate to Azure SQL. I am out of luck when trying to configure the source database in an Azure Database Migration project...
I tried to specify the service endpoint including the exposed port (since the dockerized SQL Server container´s public port is not 1433). I can connect to the SQL Server instance using SSMS from my workstation with no error, so connectivity is not the problem at all; does the Azure Database Migration require port 1433, or if not, how can I correctly specify a different port?
These are the error details I got from source details configuration in the Azure portal:
Error Type
Failed to connect, please check error details
Error Detail
Collector 'Microsoft.SqlServer.Advisor.SqlQueries.Contracts.Models.IQueryServerProperties' failed to collect data. 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: 25 - Connection string is not valid)
The parameter is incorrect
The source database configuration wizard is not very clear about the format of the remote server´s DNS name. Just specifying the fully qualified DNS name and port is not enough; it must contain the server´s instance name as well.
Wrong:
<DNS-name>,<port>
Correct:
<DNS-name>\<INSTANCENAME>,<port>

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