The Scenario:
A webApp (Not WebSite nor WebService) on Azure using WebAPI fails to connect to its Azure Database. There is no WebApp IP to open in the database firewall although I have opened (temporarily) 0.0.0.0 - 255.255.255.255 which did not help.
We receive the following generic error message:
"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)"
Running the Web App locally it connects to the Azure database fine.
The WebApp connects to the database through EF6.
So we know the connection string works, we know the database is accessible and the WebAPI works ... it only fails when the WebApp is placed on Azure.
How can we resolve this?
Ok, the solution is a little more complex than it needs to be. You can't get a webApp to communicate with a WebSql database without serious fudging. However, the correct although more costly solution is this:
Create a Ms SQL Database VM.
Create a Ms Windows VM for the API
Create a vNetwork and place both VMs on the network
Configure the API to use the internal IP of the network that belongs to the
Database VM
Voila.
Related
I am attempting to create the reporting services database for usage in SCCM. The reporting services installed fine (install only), but once I get to the Database tab and try to connect to the database server to create the database, it fails by timing out when trying to connect (see dialog). I am using Authentication Type: Current User - Integrated Security (domain user account loaded with permissions on that server - used by several other SQL apps).
Full text of error message:
Could not connect to server: 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: 50 - Could not open a connection to the SQL Server)
We are using two named instances, so the ports are dynamic. I have made sure all ports are active (netstat).
I also made sure of the following:
All SQL services are running and have been restarted several times
Firewall is disabled (all profiles) - shouldn't matter, because we are running setup locally
Remote connections are enabled in SSMS (again, shouldn't matter)
Named pipes is enabled (as are TCP/IP and Shared Memory); also re-ordered protocols while testing
Tried service accounts using virtual service account, local system, network service and known-good domain SQL service account
Varied Server Name by using machine name, FQDN, local IP, loopback (127.0.0.1) and LOCALHOST
I can ping the server and access IPC$ (as you would expect on the localhost)
I am inside of the SQL Server 2016 Reporting Services Configuration Manager and logged into the SQL Server on the correct instance and the Report Server is showing as Started. I can also user the Web Service URL (although it obviously gives me a DB error).
I have checked the Application Event log and SQL/Reporting Server logs without any hints of the problem.
What could be causing this issue? I have spent hours troubleshooting something that should be so easy.
I didn't realize that the Server name field when creating the database still requires the instance name even though the installation already had that embedded. It was just a matter of clicking that field and accepting the server\instance dropdown. I had the biggest face palm in a very long time.
I have an asp net core web app and SQL Server database hosted in Plesk via a hosting company.
I have deployed a copy of the web app to an Azure Linux App Service. It uses the Plesk hosted SQL Server database. When i use the Azure App Service I get a connection error when accessing the Plesk hosted database.
SqlException: 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: 40 - Could not open a connection to SQL Server)
If I use the Plesk hosted web app it connects to sql server correctly as expected. If I then immediately use the Azure Linux web app it manages to get a SQL connection! In all cases the connection string is identical. Its like it needs waking up!
How can this be the case. I am at a loss as to why this is happens. Any ideas folks?
Properly, you need to add the outbound IP addresses in Azure App Service into the firewall of SQL Server which your SQL Server database existed.
edit
You could check the following aspects on your side refer to this.
Make sure SQL Server Service is running
If a named instance, make sure SQL Server browser service is running
Make sure SQL Server is configured to allow remote connections
Examine the SQL Server error log for messages confirming that SQL is listening on the expected network interfaces and ports
Test server connectivity with PING from the client machine
Test port connectivity using TELNET or PowerShell to the server and port (from step 4) from the client machine. For example a. TELNET
1433 b. PowerShell: 1433 | % { echo ((new-object
Net.Sockets.TcpClient).Connect("YourServerName",$)) "server listening
on TCP port $" }
Check firewall settings if step 5 or 6 connectivity test fails
For more information:
Troubleshoot connecting to the SQL Server Database Engine
Networking Related Commands for Azure App Services
I have a .NET Core web application that fetches some data from a SQL Server. I connect to the SQL Server over the internet.
When I run the application with IIS Express or Kestrel, I can connect to the database server and retrieve data. I can also successfully connect to the database server using SQL Server Management Studio.
Here is the connection string I'm using:
"ConnectionStrings": {
"DefaultConnection": "Server=my-sql-server.someurl.com; Initial Catalog=my-sql-database; User ID=my-user-id; Password=my-password;"
}
But when I try to run the same website, on the same machine, in IIS, I get the following error message:
SqlException: 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 - No such host is known.)
I'm suspecting this has something to do with the dotnet core/IIS combination, and not a firewall/network/authentication issue, but I might be wrong.
The issue was simply that I was looking at the wrong connection string.
I have appsettings.json containing one connection string and appsettings.Production.json containing another.
When running the application with IIS Express or Kestrel, the first one is used, but when I publish the app and then run it under IIS, the environment is set to Production, and the production settings are used instead.
The problem was that the production connection string pointed to a database server that didn't exist anymore.
I solved this issue by adding LocalSystem to Identity in Web site Application pool.
Steps:
Select website application Pool
Right click and click Advanced Setting
Click on Identity, and change it to LocalSystem
You need to enable TCP/IP protocol on sql server. Please use following link:
Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?
Now, I have both my App Service and Database deployed in Azure, they are fine. I can browse to the site perfectly and it all seems to function.
Similarly, I've added a firewall rule in Azure to enable me to connect to the database server and query the database from my local SQL Server Management Studio.
Additionally, when I change my local web application (on my Local IIS Express server) to point to the Azure database it also works fine.
However, when I deploy the application I keep getting: "No such host is known":
[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 - No such host is
known.)] I've tried adding the IP address of the App Service to the
database server. I've even tried white listing the entire IP address
range just to completely discount that and it doesn't work either!
Any ideas?
If you're publishing from Visual Studio, make sure that you don't overwrite with a different remote connection string when deploying.
Also make sure you allow for Azure Services access.
I have created a test SQL Server 2005 database on my test Web Server. I have an ASP.Net MVC 4 web application also on that test server which connects to the test sql server database and it does this without any problems.
Now, I am trying with the local copy of the MVC application on my PC, to connect to the test database on the test Web Server. I thought I could just use the same connection string as the MVC app on the Web Server uses, however, when I copy that connection string and put it into the web config of my local MVC application, attempt to connect, and I get the 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: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)
Why would the connection string work for the MVC application on the test server, but not for my local copy of the MVC application?
Thanks for your help.
Why would the connection string work for the MVC application on the
test server, but not for my local copy of the MVC application?
Because there's a firewall preventing your computer from accessing this SQL server. Or maybe the SQL server is on a completely different network from your computer and is simply not directly accessible.
Talk to your network/SQL Server administrator for assistance.