storing database connection strings

D

djc

is it still customary to use web.config and global.asax to store connection
strings? For example storing the string in web.config and using application
start procedure in global.asax to declare a global app variable?

I'm an off and on hobby programmer and this was the last method recommended
to me. As I start new projects I try to find out and follow the recommended
practices of the day.
 
C

Chris Fulstow

Yes, that's still a good approach, you can read connection strings from
web.config using the WebConfigurationManager class.

You can now also encrypt parts of web.config, which is useful if you're
storing passwords.
 
C

Cowboy \(Gregory A. Beamer\)

I am not sure it was ever a good idea to use global.asax, as you have to
recompile to configure (not as much in 2.0, which will recompile single
files on the fly, of course). The config file is still recommended, although
it is a good idea to encrypt on teh machine you are going to run it on.
 
D

djc

thank you both. Its appreciated. Just to clarify to Cowboy I meant the
combination of web.config and global.asax... actual value in web.config and
declaring var referencing that value in global.asax so only web.config would
need to be changed when database changes.

and I will definitely check out the encryption.

thanks again.
 
O

Olaf Rabbachin

Hi,
thank you both. Its appreciated. Just to clarify to Cowboy I meant the
combination of web.config and global.asax... actual value in web.config and
declaring var referencing that value in global.asax so only web.config would
need to be changed when database changes.

I don't see why you would want to use Global.asax for the
connection-string. You can always do a ...

myCn.connectionstring=ConfigurationManager.ConnectionStrings("DBCon").ConnectionString

.... so there's no need to store it anywhere (i.e. in an Application-var).
If you store your connection-string within web.config, you don't have to
change anything *but* web.config if the connection needs to be amended.
Try adding a setting like this one in your web.config:
<connectionStrings>
<add name="DBCon" connectionString="Provider=..."/>
</connectionStrings>

Cheers,
Olaf
 
D

djc

thanks for the input.

Olaf Rabbachin said:
Hi,


I don't see why you would want to use Global.asax for the
connection-string. You can always do a ...

myCn.connectionstring=ConfigurationManager.ConnectionStrings("DBCon").ConnectionString

... so there's no need to store it anywhere (i.e. in an Application-var).
If you store your connection-string within web.config, you don't have to
change anything *but* web.config if the connection needs to be amended.
Try adding a setting like this one in your web.config:
<connectionStrings>
<add name="DBCon" connectionString="Provider=..."/>
</connectionStrings>

Cheers,
Olaf
 

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

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top