Switching Between Test and Production Database

Discussion in 'ASP .Net' started by Rasool, Apr 29, 2004.

  1. Rasool

    Rasool Guest

    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.
     
    Rasool, Apr 29, 2004
    #1
    1. Advertising

  2. Rasool

    Matt Berther Guest

    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
     
    Matt Berther, Apr 29, 2004
    #2
    1. Advertising

  3. Rasool

    Dan Brussee Guest

    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"
    <> 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.
    >
     
    Dan Brussee, Apr 29, 2004
    #3
  4. Rasool

    WJ Guest

    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" <> wrote in message
    news:...
    > 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.
    >
    >
     
    WJ, Apr 30, 2004
    #4
  5. 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.
     
    =?Utf-8?B?QjBuag==?=, Apr 30, 2004
    #5
  6. Rasool

    Matt Berther Guest

    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
     
    Matt Berther, Apr 30, 2004
    #6
  7. Rasool

    WJ Guest

    I never offerred whether it is bad or good. It is just a "way" and it is
    possible or just an opinion ...:)

    John

    "B0nj" <> wrote in message
    news:...
    > 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?
    >
     
    WJ, Apr 30, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bobrics
    Replies:
    5
    Views:
    2,539
    bobrics
    Mar 7, 2005
  2. Jerry III

    Re: Switching Between HTTP and HTTPS

    Jerry III, Oct 15, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    938
    Jerry III
    Oct 15, 2003
  3. Ryan Ternier
    Replies:
    1
    Views:
    562
    John Saunders
    Jul 25, 2004
  4. =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=

    switching from test to production and db connections

    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=, Oct 6, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    414
    =?Utf-8?B?Sm9lIGluIEF1c3RpbiwgVFg=?=
    Sep 27, 2006
  5. Replies:
    1
    Views:
    417
    Raymond DeCampo
    Aug 25, 2005
Loading...

Share This Page