I have an old .net 1.0 webapp that needs a bit of maintenance done on it. I've used the auto-upgrader to upgrade it to .net 3.5 (and also later tried 2.0) but now it can't connect to the database.
On the surface this looks like a noob connection-string problem, but I'm thinking it's more likely to be related to some subtle problem from the upgrade.
I get the generic error message:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
The source code is pretty basic, with no bells or whistles:
protected static SqlConnection objConn;
objConn = new SqlConnection(strConnectionString);
try
{
objConn.Open();
}
and also tried it as:
using (objConn = new SqlConnection(strConnectionString))
{
objConn.Open();
...
}
The connection string comes from the web.config, and using the debugger to set a break point and look through the properties of the connection before it tries to open it, I can see that its found the connection string properly:
connectionString="Data Source=XXX.XXX.XXX.XXX;Initial Catalog=XXXXXX;User ID=XXXXXX;Password=XXXXXX"
A handful of things I think I've ruled out:
The error message is the same whether connecting to Sql Server 2005 or Sql Server 2000.
No errors or warnings in the VS Error List.
The connection string is the same as a couple of other websites that also use the same database, so I know that the connection string is correct.
I've tried having it connect from my local computer (where I can connect to the databases via Sql Query Analyzer) and from the normal webserver, so it's not a firewall issue, neither is it a max-connections issue.
It's connecting to the server's IP address, so its not a computer browser issue (and other webapps can connect fine.
TCP and named pipes are the 2 network protocols enabled on the sql server.
Adding "Network Library=DBMSSOCN;" to the connection string changes the error message to include "provider: TCP Provider, error" (there was something else I changed in the connection string the other day that also had that affect, but I can't remember what now.)
I've already looked through 3 other similar posts on stack overflow:
(Can't list links here because I'm a new user, but their question ID's if someone else wants to link to them in a comment are: 63875, 1038888, 846479)
And this article on another site had some good ideas of things to try that didn't help either:
http://weblogs.sqlteam.com/tarad/archive/2008/05/23/60609.aspx
My best guess is that its something caused by the upgrade between .net versions - maybe something wrong in the web.config?
It's a C# app, pretty small/basic, but has been split into three projects.