473,396 Members | 1,683 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,396 software developers and data experts.

Where is the best place to put the connection string

Hi there.
In your opinion, where is the best place to put the connection string of a
web application?
Web.config, a constant into the code?

I'm not using a component server, so it's not an option, ok?

Tks.

Fernando
Nov 19 '05 #1
5 1656
Hello Fernando,

web.config.

Constants are to be discouraged for a dynamic piece of information such as
this. You dont want to recompile your application every time you change the
connection string, do you?

--
Matt Berther
http://www.mattberther.com
Hi there.
In your opinion, where is the best place to put the connection string
of a
web application?
Web.config, a constant into the code?
I'm not using a component server, so it's not an option, ok?

Tks.

Fernando


Nov 19 '05 #2
In the overwhelming majority of cases the best place to put the connection
string(s) is in the web.config file.
Here's what the appSettings section of your web.config would look like:

<configuration>
<appSettings>
<add key="ConnectionString"
value="Server=(local);Database=DBName;UID=sa;PWD="/>
</appSettings>
</configuration>

This is a nice way to manage it. You can change the connection string
easily without rebuilding the app or restarting IIS or anything, and the
change goes into effect immediately.

Then in your code behinds you can get the connection string like this:
Dim sConn as string
sConn = ConfigurationSettings.AppSettings("ConnectionStrin g")

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Fernando Lopes" <fernandomattarlopes@[remove]msn.com> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
Hi there.
In your opinion, where is the best place to put the connection string of a
web application?
Web.config, a constant into the code?

I'm not using a component server, so it's not an option, ok?

Tks.

Fernando

Nov 19 '05 #3
I'd put it into my Connection. ;-)

--

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

"Fernando Lopes" <fernandomattarlopes@[remove]msn.com> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
Hi there.
In your opinion, where is the best place to put the connection string of a
web application?
Web.config, a constant into the code?

I'm not using a component server, so it's not an option, ok?

Tks.

Fernando

Nov 19 '05 #4
Tks for everyone!

Fernando

"Fernando Lopes" <fernandomattarlopes@[remove]msn.com> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
Hi there.
In your opinion, where is the best place to put the connection string of a
web application?
Web.config, a constant into the code?

I'm not using a component server, so it's not an option, ok?

Tks.

Fernando

Nov 19 '05 #5
Encrypted in the web.config

http://msdn.microsoft.com/library/de...l/secmod22.asp

"Fernando Lopes" <fernandomattarlopes@[remove]msn.com> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
Hi there.
In your opinion, where is the best place to put the connection string of a
web application?
Web.config, a constant into the code?

I'm not using a component server, so it's not an option, ok?

Tks.

Fernando


Nov 19 '05 #6

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

Similar topics

3
by: mike.miller | last post by:
You could create a static class for the connection with static properties for the connection object itself and all of the associated properties. Just be aware that only one object can use a...
4
by: Ed_P. | last post by:
Hello, I have the following scenario: I have a solution with 4 projects Project1 = MainWindow (Windows EXE) Project2 = PresentationLayer (DLL) Project3 = BusinessLayer (DLL) Project4 =...
2
by: Chris Dunaway | last post by:
I have a web service that references a data class library which performs SQL Server access. Since the web service is also a class library, there is no App.Config, only Web.config. Is Web.Config...
8
by: Charlie | last post by:
Hi: My ASP.NET app opens and closes database connection in several pages. Rather than hard coding string into every page, is there a place I can put it where all pages will be able to access it....
5
by: Saulot | last post by:
Hi, Facing a big problem. In my Default.aspx page, I open a connection with ma Sql Server DataBase through my objects framework (A "SetDefaultConnectionString" property which open my...
6
by: ad | last post by:
We usually store the connection string of Web Applicaiton in Web.Config. Now I want to develop WinForm Application. Where is the better place to store the conneciton string?
4
by: Andrew | last post by:
Hello, friends, I have two questions: (1) In asp.net, where is the best place to store DB connection string? (We have .dll to handle all DB queries.) (2) Any sample source code for client...
5
by: csgraham74 | last post by:
Hi guys, Basically i have been developing in dotnet for a couple of years but ive had a few issues in regards to error handling. For example - I have a class that i call passing in a stored...
3
by: Nemisis | last post by:
Guys, I would like to write a error handler, or something, that will allow me to write to a database when an error occurs on my site. I am trying to implement this in the global.asax file a the...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.