changed sql server db name

Discussion in 'ASP .Net' started by Newbie, Jan 24, 2005.

  1. Newbie

    Newbie Guest

    Hi guys,

    Ok, i have a situation like this:
    I have a hosted asp.net web appl. On the back end, i have sql server db -
    say, mydb. In this appl, i created a connection (SQLConnection) that refer
    to this db.
    It worked fine for almost 1,5 year now.
    Now the management want to move this appl to another hosting, which dictates
    that all sql server created will be named: owner_dbName. So, in this
    particular appl, the new db would be named: myName_myDb.
    I have changed the connection string in my web.config to refer to the new db
    name, it's not working since i create a SQLconnection in every page i
    created. The only way is that i have to change the connection setting in
    every page to refer to new db name. Now, that would be very tedious, since i
    have around 50 pages of it. Not to mention the possibilities if one day the
    management would move to another hosting company with yet another sql server
    naming policy.
    Is there any simple way to change this?

    I'll appreciate any helps.

    thks in advance,
    andy
     
    Newbie, Jan 24, 2005
    #1
    1. Advertising

  2. Hi,

    I assume from what you're saying that you store the connection string
    you use to connect to the db in your web.config file. This is good
    (some say bad for security reasons and you should store the connection
    string elsewhere, e.g. in the registry. however, i'm sure your hosting
    company won't give you access to that!). It's good because then you
    store the connection string in one place and if this sort of thing
    happens you only have to change one string in one place.

    You mention you've got to go through every page and change your
    SQLConnection? Doesn't each page use the connection string in your
    web.config file?

    If not, I would advise you modify your site to always use the
    connection string in your web.config - therefore meaning you don't have
    to edit 50+ files next time your hosting company decides to rename all
    databases.

    Regards,

    Peter Chadwick (MCP)
     
    Peter Chadwick (MCP), Jan 24, 2005
    #2
    1. Advertising

  3. Newbie

    Newbie Guest

    Thanks for the reply Pete,

    Yes, it's true that i created a connection string in my web.config. But, in
    every page that access sql data, i dropped a sqlconnection component and
    point it to the connection that i set within server explorer. And I refer to
    it for all sqldataadapter, sqlcommand that I created within that page. I
    thought that this will reflect the connection string in my web.config. Until
    this time, when i need to move it elsewhere.
    So, ok, I think that you made a point here to always use the conn string
    that i set in web.config. But how to do it? Can you pls give me an example,
    as i'm new to it.

    Thks & brgds,
    andy


    "Peter Chadwick (MCP)" <> wrote in message
    news:...
    > Hi,
    >
    > I assume from what you're saying that you store the connection string
    > you use to connect to the db in your web.config file. This is good
    > (some say bad for security reasons and you should store the connection
    > string elsewhere, e.g. in the registry. however, i'm sure your hosting
    > company won't give you access to that!). It's good because then you
    > store the connection string in one place and if this sort of thing
    > happens you only have to change one string in one place.
    >
    > You mention you've got to go through every page and change your
    > SQLConnection? Doesn't each page use the connection string in your
    > web.config file?
    >
    > If not, I would advise you modify your site to always use the
    > connection string in your web.config - therefore meaning you don't have
    > to edit 50+ files next time your hosting company decides to rename all
    > databases.
    >
    > Regards,
    >
    > Peter Chadwick (MCP)
    >
    >
     
    Newbie, Jan 24, 2005
    #3
  4. Hi,

    Here is a quick sample (C#) of a SQLConnection getting the connection
    string out of the web.config. If you're connection string is in the
    appSettings section of your web.config the following should work:

    string connectionString =
    ConfigurationSettings.AppSettings["ConnectionString"];
    SqlConnection connection = new SqlConnection(connectionString);

    Hope this helps some,
    Regards,

    Peter Chadwick (MCP)
     
    Peter Chadwick (MCP), Jan 25, 2005
    #4
    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.

Share This Page