473,473 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2113
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
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...
1
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...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.