Question

I'm experiencing a strange issue in my ASP.NET MVC application where my connection string works fine in development on my local machine, but fails to connect to the SQL Server 2008 R2 database when deployed on Windows Server 2008. The database I am trying to connect to resides on a Windows Server 2003 machine. Both machines are on the same network. Here is the connection string in my web.config file:

<connectionStrings>
    <add name="MyDatabase" connectionString="data source=MyServerName;Initial Catalog=MyAppDB;User Id=sqluseraccount;Password=mypassword" providerName="System.Data.SqlClient" />
</connectionStrings>

I am using plain old ADO.NET to query the database, so my methods look like this:

string connectionString = ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString;

using (SqlConnection conn = new SqlConnection(connectionString))
{
    // Code to query the database here
}

I know the connection string is fine because it works on my local machine and in an MVC application deployed to the same server where the SQL database resides. I know the MVC application works because I can correctly request any page where a database call is not required. I'm at a loss for what could be going on. There are other applications (mainly Java) on the Windows Server 2008 machine that can connect to this same database without error.

I'm hoping someone here can point me in the right direction to resolve this.

Was it helpful?

Solution

I figured out the problem. Turns out the web.config file from one of the Java applications was overriding the MVC application's web.config file even though they were running on different app pools. Apparently this was caused by the configuration of the Apache Tomcat connector installed on the server. Moving the connection string to the Java application's web.config file solved the issue temporarily.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top