469,927 Members | 1,710 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Store Connection Settings in a config file


C#

I am trying to store my connection settings in a config file, mainly so I
can easily change the db that the app connects to without doing a release of
code. I have the config file sorted fine, and I can read the connection
string in and connect. But at the moment everytime a connection is made to
the database to get records, update records insert records etc etc, this file
has to be read back in again. Is this an ok way of doing it, or is there a
better method? Maybe retrieving the string once at login, and somehow
storing it in a global parameter of some kind?? Would storing it in the
reigstry be any better? Is there a performance hit with this, or should I
just settle for this constant disk read?

Thanks

Ste
Sep 27 '05 #1
4 2516
JP
You could store your connection as an application veriable that is only read
from the config file once.

web config...

<appSettings>
<add key="myConString" value="Persist Security Info=False;Network=dbmssocn;
User ID=myUser;Password=myPassword;Initial Catalog=myDatabase;Data
Source=myserver" />
</appSettings>
ASPX...
Session["ConnectionString"] =
ConfigurationSettings.AppSettings.Get("myConString ")
--
JP
..NET Software Develper
"Steve" wrote:

C#

I am trying to store my connection settings in a config file, mainly so I
can easily change the db that the app connects to without doing a release of
code. I have the config file sorted fine, and I can read the connection
string in and connect. But at the moment everytime a connection is made to
the database to get records, update records insert records etc etc, this file
has to be read back in again. Is this an ok way of doing it, or is there a
better method? Maybe retrieving the string once at login, and somehow
storing it in a global parameter of some kind?? Would storing it in the
reigstry be any better? Is there a performance hit with this, or should I
just settle for this constant disk read?

Thanks

Ste

Sep 27 '05 #2
JP
Oh forgot:
need to add:

using Ststem.Configuration;

--
JP
..NET Software Develper
"Steve" wrote:

C#

I am trying to store my connection settings in a config file, mainly so I
can easily change the db that the app connects to without doing a release of
code. I have the config file sorted fine, and I can read the connection
string in and connect. But at the moment everytime a connection is made to
the database to get records, update records insert records etc etc, this file
has to be read back in again. Is this an ok way of doing it, or is there a
better method? Maybe retrieving the string once at login, and somehow
storing it in a global parameter of some kind?? Would storing it in the
reigstry be any better? Is there a performance hit with this, or should I
just settle for this constant disk read?

Thanks

Ste

Sep 27 '05 #3
How do i implement this kind of thing into a windows app?

Thanks

"JP" wrote:
You could store your connection as an application veriable that is only read
from the config file once.

web config...

<appSettings>
<add key="myConString" value="Persist Security Info=False;Network=dbmssocn;
User ID=myUser;Password=myPassword;Initial Catalog=myDatabase;Data
Source=myserver" />
</appSettings>
ASPX...
Session["ConnectionString"] =
ConfigurationSettings.AppSettings.Get("myConString ")
--
JP
.NET Software Develper
"Steve" wrote:

C#

I am trying to store my connection settings in a config file, mainly so I
can easily change the db that the app connects to without doing a release of
code. I have the config file sorted fine, and I can read the connection
string in and connect. But at the moment everytime a connection is made to
the database to get records, update records insert records etc etc, this file
has to be read back in again. Is this an ok way of doing it, or is there a
better method? Maybe retrieving the string once at login, and somehow
storing it in a global parameter of some kind?? Would storing it in the
reigstry be any better? Is there a performance hit with this, or should I
just settle for this constant disk read?

Thanks

Ste

Sep 27 '05 #4
JP
Hope this helps:

http://msdn2.microsoft.com/en-us/library/ms134260

This explain how to access the configuration manger via a client app. Sorry,
so used to web apps didnt think to ask.
--
JP
..NET Software Develper
"Steve" wrote:
How do i implement this kind of thing into a windows app?

Thanks

"JP" wrote:
You could store your connection as an application veriable that is only read
from the config file once.

web config...

<appSettings>
<add key="myConString" value="Persist Security Info=False;Network=dbmssocn;
User ID=myUser;Password=myPassword;Initial Catalog=myDatabase;Data
Source=myserver" />
</appSettings>
ASPX...
Session["ConnectionString"] =
ConfigurationSettings.AppSettings.Get("myConString ")
--
JP
.NET Software Develper
"Steve" wrote:

C#

I am trying to store my connection settings in a config file, mainly so I
can easily change the db that the app connects to without doing a release of
code. I have the config file sorted fine, and I can read the connection
string in and connect. But at the moment everytime a connection is made to
the database to get records, update records insert records etc etc, this file
has to be read back in again. Is this an ok way of doing it, or is there a
better method? Maybe retrieving the string once at login, and somehow
storing it in a global parameter of some kind?? Would storing it in the
reigstry be any better? Is there a performance hit with this, or should I
just settle for this constant disk read?

Thanks

Ste

Sep 27 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Chris Dunaway | last post: by
5 posts views Thread by Guadala Harry | last post: by
1 post views Thread by amber | last post: by
10 posts views Thread by Paul Cheetham | last post: by
4 posts views Thread by Rob | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.