0

I keep getting an error when trying to access the database from a web site it returns an error that it can't find the server or it's inaccessible.

Now I did a search and I found many possible reasons - I turned on named pipes and also did what this link suggested (i.e. set the IP addresses to "enabled") yet I'm still getting the error.

Error SqlException: System.Data.SqlClient.SqlException (0x80131904): Error An error has occurred with the network or the occurrence when connecting to SQL Server. Can not find server or is not available. Verify that the instance name is correct and that the configuration of SQL Server allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at

I also downloaded this little app and I copy/pasted the connection string from the web.config used in IIS for this site and the app is able to connect and query the same database being targeted by the web site.

And, as the title says, this error is utterly missing when I debug it in VS2010. What could be causing this error when launching from the server?

Edit: the connection string includes a user name and password (it's not Windows Authentication).

Community
  • 1
  • 1
Alex In Paris
  • 1,017
  • 9
  • 19
  • 1
    If you continue to run into a wall with this, some possible approach can be to (a) implement some verbose logging before deploying and test that out or (b) install and run Visual Studio Remote Debugger on the server and attach to the process, debug straight on the server. The little app you downloaded, it can connect to the database from the server directly, right, not your machine? Meaning you have verified SQL server is accessible from your web server? – Dmitriy Khaykin Jan 29 '14 at 00:43
  • Yes, the app is on the server and, while using the same connection string the server uses, it is able to query the database. – Alex In Paris Jan 29 '14 at 08:13
  • 1
    Time for remote debugger. Only other thing I can think of, and this is if your app uses Linq-To-Sql and the generated DataContext, sometimes even when your config is correct, it will cache the connection string somehow and use your local connectionString from when you were doing development instead of the one from config, you need to remove the default conn string in that case and recompile/redeploy so to force it to pull from app.config. – Dmitriy Khaykin Jan 29 '14 at 08:17
  • It just clicked when you wrote "app.config"... Answer below. – Alex In Paris Jan 29 '14 at 08:36

2 Answers2

0

Most likely a security issue. If using windows authentication then make sure the thread pool that the web application is running as has sufficient DB access\privileges.

Mikee
  • 1,571
  • 2
  • 14
  • 24
0

The issue is that the web.config references another config file

<appSettings file="config/dev.config">

and so the connection string in web.config is ignored over the one in dev.config - an error to have it in both (the one on the test server was created by someone else and worked on static pages - it only failed when the website had to query the database), that's why the version in Visual Studio was running fine.

Alex In Paris
  • 1,017
  • 9
  • 19