473,397 Members | 2,099 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.

connection string

where is the best place to put the connection string for use through-out my
app?
right now I use, in every page/sub/etc:
SqlConnect = New SqlConnection("Server=xxxx;uid=xxx;pwd=xxxx;databa se=xxx")
for sql server 2k connection

This connection is for all users,and is the only connection for this app.

maybe in the Global.asax or webconfig file???

thanx!
Nov 19 '05 #1
9 2110
web.config is the best place:

<appSettings>
<add key="connectionString" value="1" />
</appSettings>

under the <configuration> root element. You can then access it via
System.Configuration.ConfigurationSettings.AppSett ings("connectionString")
in vb.Net and with [ ] in c#

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:D2**********************************@microsof t.com...
where is the best place to put the connection string for use through-out my app?
right now I use, in every page/sub/etc:
SqlConnect = New SqlConnection("Server=xxxx;uid=xxx;pwd=xxxx;databa se=xxx") for sql server 2k connection

This connection is for all users,and is the only connection for this app.

maybe in the Global.asax or webconfig file???

thanx!

Nov 19 '05 #2
Vko
The configuration file is the best choice.

"Chris" wrote:
where is the best place to put the connection string for use through-out my
app?
right now I use, in every page/sub/etc:
SqlConnect = New SqlConnection("Server=xxxx;uid=xxx;pwd=xxxx;databa se=xxx")
for sql server 2k connection

This connection is for all users,and is the only connection for this app.

maybe in the Global.asax or webconfig file???

thanx!

Nov 19 '05 #3
The last project I worked on we held the value in web.config but used the
Application_Start event to populate a global variable.

Was this "worth" it? Or should we have just stuck with GetConfiguration
calls each time?

My thinking was get the valule in memory and save the file read each time...

What do you guys think?

al*****@yahoo.com

"Chris" wrote:
where is the best place to put the connection string for use through-out my
app?
right now I use, in every page/sub/etc:
SqlConnect = New SqlConnection("Server=xxxx;uid=xxx;pwd=xxxx;databa se=xxx")
for sql server 2k connection

This connection is for all users,and is the only connection for this app.

maybe in the Global.asax or webconfig file???

thanx!

Nov 19 '05 #4
Vko
In my projects I use an utility class like that :

public sealed class Settings
{
private static string connectionString = "";

public static string ConnectionString
{
get { return connectionString; }
}

static Settings ()
{
ConnectionString = ...AppSettings["connectionString"];
}

}

"alaspin" wrote:
The last project I worked on we held the value in web.config but used the
Application_Start event to populate a global variable.

Was this "worth" it? Or should we have just stuck with GetConfiguration
calls each time?

My thinking was get the valule in memory and save the file read each time...

What do you guys think?

al*****@yahoo.com

"Chris" wrote:
where is the best place to put the connection string for use through-out my
app?
right now I use, in every page/sub/etc:
SqlConnect = New SqlConnection("Server=xxxx;uid=xxx;pwd=xxxx;databa se=xxx")
for sql server 2k connection

This connection is for all users,and is the only connection for this app.

maybe in the Global.asax or webconfig file???

thanx!

Nov 19 '05 #5
i agree with vko, depending on what you mean by "global variable" was it
just a static field (good) or using the Application object (bad) ?

Also, not that the web.config is cached internally...so perf won't change
much..more about usability...and I think vko's example provides the greatest
abstraction.

For the record, I only ever use custom configurations, so that's how I do
it:
http://openmymind.net/Configuration/index.html

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Vko" <Vk*@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...
In my projects I use an utility class like that :

public sealed class Settings
{
private static string connectionString = "";

public static string ConnectionString
{
get { return connectionString; }
}

static Settings ()
{
ConnectionString = ...AppSettings["connectionString"];
}

}

"alaspin" wrote:
The last project I worked on we held the value in web.config but used the Application_Start event to populate a global variable.

Was this "worth" it? Or should we have just stuck with GetConfiguration
calls each time?

My thinking was get the valule in memory and save the file read each time...
What do you guys think?

al*****@yahoo.com

"Chris" wrote:
where is the best place to put the connection string for use through-out my app?
right now I use, in every page/sub/etc:
SqlConnect = New SqlConnection("Server=xxxx;uid=xxx;pwd=xxxx;databa se=xxx") for sql server 2k connection

This connection is for all users,and is the only connection for this app.
maybe in the Global.asax or webconfig file???

thanx!

Nov 19 '05 #6
Yes, we lobbed it into the Application object (old ASP habit)

Good point about the cacheing - thnaks guys

al*****@yahoo.com

"Karl Seguin" wrote:
i agree with vko, depending on what you mean by "global variable" was it
just a static field (good) or using the Application object (bad) ?

Also, not that the web.config is cached internally...so perf won't change
much..more about usability...and I think vko's example provides the greatest
abstraction.

For the record, I only ever use custom configurations, so that's how I do
it:
http://openmymind.net/Configuration/index.html

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Vko" <Vk*@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...
In my projects I use an utility class like that :

public sealed class Settings
{
private static string connectionString = "";

public static string ConnectionString
{
get { return connectionString; }
}

static Settings ()
{
ConnectionString = ...AppSettings["connectionString"];
}

}

"alaspin" wrote:
The last project I worked on we held the value in web.config but used the Application_Start event to populate a global variable.

Was this "worth" it? Or should we have just stuck with GetConfiguration
calls each time?

My thinking was get the valule in memory and save the file read each time...
What do you guys think?

al*****@yahoo.com

"Chris" wrote:

> where is the best place to put the connection string for use through-out my > app?
> right now I use, in every page/sub/etc:
> SqlConnect = New SqlConnection("Server=xxxx;uid=xxx;pwd=xxxx;databa se=xxx") > for sql server 2k connection
>
> This connection is for all users,and is the only connection for this app. >
> maybe in the Global.asax or webconfig file???
>
> thanx!


Nov 19 '05 #7
When you store it in web.config, it *is*
in memory after the application starts.

web.config is loaded into memory
as soon Application_OnStart initializes.

Juan T. Llibre
ASP.NET MVP
===========
"alaspin" <al*****@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
The last project I worked on we held the value in web.config but used the
Application_Start event to populate a global variable.

Was this "worth" it? Or should we have just stuck with GetConfiguration
calls each time?

My thinking was get the valule in memory and save the file read each
time...

What do you guys think?

al*****@yahoo.com

"Chris" wrote:
where is the best place to put the connection string for use through-out
my
app?
right now I use, in every page/sub/etc:
SqlConnect = New
SqlConnection("Server=xxxx;uid=xxx;pwd=xxxx;databa se=xxx")
for sql server 2k connection

This connection is for all users,and is the only connection for this app.

maybe in the Global.asax or webconfig file???

thanx!

Nov 19 '05 #8
thanx guys, this did the trick. I also added this to my custom dll that I add
to my project to control login. Works like a charm.

"Karl Seguin" wrote:
web.config is the best place:

<appSettings>
<add key="connectionString" value="1" />
</appSettings>

under the <configuration> root element. You can then access it via
System.Configuration.ConfigurationSettings.AppSett ings("connectionString")
in vb.Net and with [ ] in c#

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:D2**********************************@microsof t.com...
where is the best place to put the connection string for use through-out

my
app?
right now I use, in every page/sub/etc:
SqlConnect = New

SqlConnection("Server=xxxx;uid=xxx;pwd=xxxx;databa se=xxx")
for sql server 2k connection

This connection is for all users,and is the only connection for this app.

maybe in the Global.asax or webconfig file???

thanx!


Nov 19 '05 #9
Check out this faq,
http://www.extremeexperts.com/Net/FA...ionString.aspx

--
-Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com

"Chris" <Ch***@discussions.microsoft.com> wrote in message
news:D2**********************************@microsof t.com...
where is the best place to put the connection string for use through-out my app?
right now I use, in every page/sub/etc:
SqlConnect = New SqlConnection("Server=xxxx;uid=xxx;pwd=xxxx;databa se=xxx") for sql server 2k connection

This connection is for all users,and is the only connection for this app.

maybe in the Global.asax or webconfig file???

thanx!

Nov 19 '05 #10

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

Similar topics

0
by: iKiLL | last post by:
Hi All Code Below for this problem ERROR: "An existing connection was forcibly closed by the remote host"
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
3
by: ninjamonkey | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
0
by: Robert Avery | last post by:
In VBA/VB6, I had a class (incomplete sample below) that watched and displayed for the user all connection events, so that I could easily see what SQL was taking a long time, and when it freezes, I...
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
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
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...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.