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.
Related
I have two ASP.NET MVC applications that connect to the same Azure SQL Server database. I've used both for a long time.
I recently reinstalled my local machine and got the files for both applications from TFS. One of them works with the database just fine. The other one can connect to the database using Visual Studio's Server Explorer using the EF connection string, but when I try to run it locally I get error 26:
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)
I have checked my local IP is allowed through the Azure firewall. Any ideas why the second application won't run locally? A port issue or a cached file?
Thanks
My app is a small test application and I only used it locally so I never implemented the Owin Identity that was included in the generated project.
I had updated Visual Studio when I updated to Windows 10. Perhaps that made the Owin Identity mandatory. When I added a connection string for the identity system the app worked without issue again.
So it was an issue with the connection string, just not the EF connection string.
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.
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.
I have an MVC4 app that was working before I started working on it today. As far as I know I did not make any changes to the connection strings.
I have a connection string set to use a SQL Server 2012 database.
When trying to run the app from my local machine I get this 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)
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
SQLExpress database file auto-creation error:
The connection string specifies a local SQL Server Express instance using a database location within the application's App_Data directory. The provider attempted to automatically create the application services database because the provider determined that the database does not exist. The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database:
Sql Server Express must be installed on the machine.
If I run the app from the server that it resides on I do not get this error. I can also access the SQL Server database from both my local machine and the server with SQL Server Management Studio and Visual Studios built in Server Explorer.