Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Switching Between Test and Production Database

Reply
Thread Tools

Switching Between Test and Production Database

 
 
Rasool
Guest
Posts: n/a
 
      04-29-2004
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.


 
Reply With Quote
 
 
 
 
Matt Berther
Guest
Posts: n/a
 
      04-29-2004
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
 
Reply With Quote
 
 
 
 
Dan Brussee
Guest
Posts: n/a
 
      04-29-2004
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"
<(E-Mail Removed)> 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.
>


 
Reply With Quote
 
WJ
Guest
Posts: n/a
 
      04-30-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
=?Utf-8?B?QjBuag==?=
Guest
Posts: n/a
 
      04-30-2004
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.
 
Reply With Quote
 
Matt Berther
Guest
Posts: n/a
 
      04-30-2004
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
 
Reply With Quote
 
WJ
Guest
Posts: n/a
 
      04-30-2004
I never offerred whether it is bad or good. It is just a "way" and it is
possible or just an opinion ...

John

"B0nj" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
Process Switching vs. Fast/CEF Switching? asdf Cisco 7 05-29-2007 05:26 PM
switching from test to production and db connections =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= ASP .Net 4 09-27-2006 07:24 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments