changed sql server db name

N

Newbie

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
 
P

Peter Chadwick (MCP)

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 address removed)
 
N

Newbie

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
 
P

Peter Chadwick (MCP)

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 address removed)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top