473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

storing database connection strings

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.
Oct 26 '06 #1
5 1767
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.

djc wrote:
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.
Oct 26 '06 #2
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.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************************************************
Think outside of the box!
*************************************************
"djc" <no***@nowhere.comwrote in message
news:ez****************@TK2MSFTNGP05.phx.gbl...
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.

Oct 26 '06 #3
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.

"djc" <no***@nowhere.comwrote in message
news:ez****************@TK2MSFTNGP05.phx.gbl...
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.

Oct 26 '06 #4
Hi,

djc wrote:
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.Connect ionStrings("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
--
My .02: www.Resources.IntuiDev.com
Oct 26 '06 #5
djc
thanks for the input.

"Olaf Rabbachin" <Ol*********@IntuiDev.comwrote in message
news:us****************@TK2MSFTNGP04.phx.gbl...
Hi,

djc wrote:
>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.Connect ionStrings("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
--
My .02: www.Resources.IntuiDev.com

Oct 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ben M. | last post by:
Greetings all, This should be an easy task, and Im sure it is, but as many times as I have tried, I cant seem to get this to work properly. We changed ISPs recently from a shared host to a...
4
by: Minh Tran | last post by:
In order to minimize the number of connection strings I have to use to access different databases on the same Sql Server, I was considering storing all stored procedures in just one database. I...
1
by: Ritu | last post by:
How to store connection strings in machine.config?What are the advantages of storing it in the machine.config file.Can u provide me with the information regarding accessibility of machine.config...
2
by: Shyam | last post by:
Hi, I wanted some advice on the following. All the users who log in to the system are created in the SQL Server. As I am not keen to store any user information on the web.config file for...
3
by: Ben | last post by:
Hi all I have made a vb.net windows app that works great in design. But after deploying the app on the same design computer (my own) the app can not find any of the two databases it needs to...
5
by: hfk0 | last post by:
Hi, I'm new to ASP.net, SQL Server and visual studio.net, and I'm having problem inserting and storing data from a web form to a SQL database. I created a simple ASP.NET web form, a simple SQL...
0
bartonc
by: bartonc | last post by:
With one small change to the view/control: self.staticText3 = wx.StaticText(id=wxID_DBCONNECTDIALOGSTATICTEXT3, label='ODBC Data Source Name', name='staticText3',...
4
by: shapper | last post by:
Hello, I am using Microsoft Enterprise Library, on a class, to connect to a database as follows: Dim db As Database = DatabaseFactory.CreateDatabase("DatabaseName") However, I would like...
5
by: Alan Silver | last post by:
Hello, Server configuration: Windows 2003 Server SP2 SQL Server 2000 SP4 ..NET v2.0.50727 just built up a new server using the same configuration as my current one. I even used the same CDs...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.