Store Connection Settings in a config file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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")
 
How do i implement this kind of thing into a windows app?

Thanks

JP said:
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 said:
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
 
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 said:
How do i implement this kind of thing into a windows app?

Thanks

JP said:
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 said:
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
 
Back
Top