473,503 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ 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 2114
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
3529
by: iKiLL | last post by:
Hi All Code Below for this problem ERROR: "An existing connection was forcibly closed by the remote host"
6
8138
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
2090
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
1962
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
7199
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
7273
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
7322
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...
1
6982
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
3161
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
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.