Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > changed sql server db name

Reply
Thread Tools

changed sql server db name

 
 
Newbie
Guest
Posts: n/a
 
      01-24-2005
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


 
Reply With Quote
 
 
 
 
Peter Chadwick (MCP)
Guest
Posts: n/a
 
      01-24-2005
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)
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
Newbie
Guest
Posts: n/a
 
      01-24-2005
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)" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> 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)
> (E-Mail Removed)
>



 
Reply With Quote
 
Peter Chadwick (MCP)
Guest
Posts: n/a
 
      01-25-2005
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)
(E-Mail Removed)

 
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
How to remote connect to the SQL server 2005 when th ere is a‘\’ in the SQL server name, such as 192.168.0.1 1\active? Wesley Chen Ruby 9 04-14-2009 11:36 AM
How to remote connect to the SQL server 2005 when th ere is a‘\’ in the SQL server name, such as 192.168.0.1 1\active? Wesley Chen Ruby 0 04-07-2009 10:23 AM
Help. Getting a An error has occurred while establishing a connectionto the server. When connecting to SQL Server 2005, this failure may be causedby the fact that under the default settings SQL Server does not allow remote aboutjav.com@gmail.com ASP .Net 0 05-03-2008 12:43 PM
xmlDocument.Save "&#10;" getting changed changed to "&amp;#10" st@jpa.co.jp ASP .Net 1 10-11-2005 01:30 PM



Advertisments