App.config connection String

  • Thread starter Thread starter Lit
  • Start date Start date
L

Lit

Hi,

in C# 2005 are we still using <appSettings> section or have we moved to a
new configuration section that is better to use like <connectionStrings>
</connectionStrings>


How do I use the later from Code?


Thank You,

Lit
 
Hi,

both methods are still valid, just that by using appSettings you get a
warning.


You can store your connection strings in the connectionStrings section of
the config file and have access to them from the code by using


ConnectionStringSettings settings;
settings =
ConfigurationManager.ConnectionStrings["DatabaseConnection"];

settings.ConnectionString will give you the actual connection.
 
Ignacio,

can not find ConnectionStringSettings under System.Configuration namespace.

Lit

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

both methods are still valid, just that by using appSettings you get a
warning.


You can store your connection strings in the connectionStrings section of
the config file and have access to them from the code by using


ConnectionStringSettings settings;
settings =
ConfigurationManager.ConnectionStrings["DatabaseConnection"];

settings.ConnectionString will give you the actual connection.


Lit said:
Hi,

in C# 2005 are we still using <appSettings> section or have we moved to
a new configuration section that is better to use like
<connectionStrings> </connectionStrings>


How do I use the later from Code?


Thank You,

Lit
 
Sorry, was missing Add Reference to the System.Configuration Assembly.
I thought it would be there if I use

using System.Configuration; // in addition I had to add the Assembly.

Thank you,



Lit





Lit said:
Ignacio,

can not find ConnectionStringSettings under System.Configuration
namespace.

Lit

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

both methods are still valid, just that by using appSettings you get a
warning.


You can store your connection strings in the connectionStrings section of
the config file and have access to them from the code by using


ConnectionStringSettings settings;
settings =
ConfigurationManager.ConnectionStrings["DatabaseConnection"];

settings.ConnectionString will give you the actual connection.


Lit said:
Hi,

in C# 2005 are we still using <appSettings> section or have we moved to
a new configuration section that is better to use like
<connectionStrings> </connectionStrings>


How do I use the later from Code?


Thank You,

Lit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top