Hello Rasool,
One solution might be to pass a querystring parameter indicating that you want to run the test database.
http://localhost/myapp/default.aspx?db=test
You could set a session variable basedon this in Session_Start and have a database connection factory object that pulls the appropriate string from the web.config.
class ConnectionFactory
{
public static string GetConnectionString()
{
string connString = ConfigurationSettings.AppSettings["prodKeyName"];
if (Session["db"] == "test")
{
connString = ConfigurationSettings.AppSettings["testKeyName"];
}
return connString;
}
}
Anywhere that you are using the connection string, simply change the code to call ConnectionFactory.GetConnectionString(). This would allow you to work in additional databases as you need. Let's say you want to incorporate a staging database.
None of your other code would change, you'd simple add the correct check to the factory method.
Hi,
We have an asp.net application that we constanly use to query some
data from two servers (one prod and the other test). Everytime we have
to go to web.config and change the connection string to point to a
different database. Not to mention that while we are on the test
database no one can use that same application for prodution. We don't
want to move the whole application to a different location (i.e
creating a new web site) for maintenance issue. Is there a way to have
two URL pointing to the same asp.net application but using two
web.config, so that by changing the URL the only thing we are acually
changing is the database? Thanks.
--
--
Matt Berther
http://www.mattberther.com