473,396 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Switching Between Test and Production Database

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.
Nov 18 '05 #1
6 1550
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
Nov 18 '05 #2
web.config is just a convenient place to keep connection strings. You
can do whatever you need to do to get connected. Two web.config
settings and a session var, or whatever you decide to do. Maybe have a
master database that points to other databases?

On Thu, 29 Apr 2004 14:04:36 -0700, "Rasool"
<ra**************@translink.bc.ca> wrote:
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.


Nov 18 '05 #3
WJ
You can create a sub-web under the current production web site. Then build a
separate "Web.Config" file that references your Test DB under the sub-web
folder. Finally, create a link label from your home page (production) to
lead your users into the test sub-web site where your page loader would open
its own database using its own Web.Config file.

John

"Rasool" <ra**************@translink.bc.ca> wrote in message
news:uj**************@tk2msftngp13.phx.gbl...
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.

Nov 18 '05 #4
Why oh why are you hardcoding the servername into the web.config file? A solution I implement is to have an Access database containing a list of all servers my apps might need to use. For me, this database is on a network share that everyone has access to, but for a web app it could just as easily be on the web server's hard disk - c:\inetpub\wwwroot\data\servers.mdb for instance
You can then easily have a page from which the user can select the server they want to use, and you can build the connection string dynamically from there
But hard-coding the server name in the web.config... that's just, well - bad.
Nov 18 '05 #5
Hello =?Utf-8?B?QjBuag==?=,

Why oh why are you hardcoding the servername into the web.config file?
A solution I implement is to have an Access database containing a list
of all servers my apps might need to use. For me, this database is on
a network share that everyone has access to, but for a web app it
could just as easily be on the web server's hard disk -
c:\inetpub\wwwroot\data\servers.mdb for instance.
I disagree. This is exactly what the web.config is for (things an application needs to run).
You can then easily have a page from which the user can select the
server they want to use, and you can build the connection string
dynamically from there.


Why couldnt this be done with an IConfigurationSectionHandler that lists all the servers. This way, you could use the easier ConfigurationSettings API and also not worry about remembering to deploy an additional file?

--
Matt Berther
http://www.mattberther.com
Nov 18 '05 #6
WJ
I never offerred whether it is bad or good. It is just a "way" and it is
possible or just an opinion ...:)

John

"B0nj" <an*******@discussions.microsoft.com> wrote in message
news:A6**********************************@microsof t.com...
That's even worse than the other two answers - doesn't he have to then maintain a separate subweb for each and every database he wants to support?

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: The Mighty Chaffinch | last post by:
I want to have 2 completely separate instances of my ASP/Access application running on the same web server. One will be a live production application, and the other part of a system test...
2
by: Justin Allen | last post by:
SQL 2000, Windows 2000. I need to find a way to export our data from our production database and import it into a test database. I can do it to a freshly created test database I just have trouble...
4
by: Jeremy Holt | last post by:
Hi, In a windows.forms application I would BeginInvoke a delegate on the UI thread to collect data from a database. When the call returns to the AsyncCallback, if the Control.InvokeRequired =...
4
by: WebBuilder451 | last post by:
I have a project that i built using vs.net. The database connections were created using drag and drop. Rather than deleting the connections and re-creating the connections to the production server...
1
by: TeeCo | last post by:
Hi folks. I'm trying to change the location of the Access mdb file I connect to using OleDb and am having trouble. I'm using Visual C# 2005 and the default values I use for the ConnectionString...
11
by: brett | last post by:
I use two test servers and one production. I have a Utilities class that holds many of the links used through the site. One of the variables in this class is assigned the domain name. I need to...
2
by: Tom_F | last post by:
To comp.databases.ms-access -- I'm running Microsoft Access 2003 on Windows XP Professional. I have a "Test" version and a "Production" version of our database, with the same dataset name, but...
2
by: Brian | last post by:
Hello, I have an app where I am switching between development mode and live mode, phyically seperate networks. What I would like to try and figure out is, how can I have my app know which db...
2
by: programmerx101 | last post by:
Ok, I'm looking for expert advice on this one. I have a database which keeps going into read_only mode. Sometimes it goes into read_only / single user mode. Once it was taken offline completely....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.