Domanda

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).

È stato utile?

Soluzione 2

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top