IIS can't connect to SQL Server, but an external PC can


My VB.Net code connects to SQL Server. On my PC, it succeeds. On IIS running on the same machine as SQL Server, it fails. Any ideas?

I've tested:

  • I've tried IP address and server name. Same result.
  • I've tried Integrated Security and I've tried username/password. Same result.
  • On the server machine, Excel and SSMS can connect to SQL server using the same server name, username and password.
  • The fact that my PC can connect excludes many common problems including: ip address, server name, port, firewall, turn on sql server, connection string, credentials, permissions, sql roles.

Server (IIS and SQL) info: VB.Net, connection string providerName="System.Data.SqlClient", Windows Server 2008 SP2.

My PC info: Run website in Visual Studio 2019. Connects to same DB using same connection string (not local db and not as a different user).

Code (fails on second line):
oConn = ConnectionService.DatabaseName.Connect

Connection string: connectionString="Data Source=IP Address\SQLEXPRESS;Initial Catalog=DatabaseName;Integrated Security=False;Persist Security Info=False;User ID=Username;Password=Password;" providerName="System.Data.SqlClient"

Error message: System.Data.SqlClient.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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (0x80004005): The network path was not found

asked on Stack Overflow May 27, 2020 by Tim von Ahsen

1 Answer


Oops. Right after posting this, I found out Web.Config pointed to a different connection string. That should explain and solve everything. I had checked Web.Config, but it turns out that that wasn't the one this server was using.

answered on Stack Overflow May 27, 2020 by Tim von Ahsen

User contributions licensed under CC BY-SA 3.0