Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reading values from app.config
Message
De
31/03/2013 04:04:03
 
 
À
30/03/2013 14:04:59
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 4.0
Divers
Thread ID:
01569562
Message ID:
01569578
Vues:
29
>Hi,
>
>this has to be really simple, but my searching is only turning up things that do not appear to work.
>
>I have an app.config file with the following:
>
>
<?xml version="1.0" encoding="utf-8" ?>
><configuration>
>  <appsettings>
>    <add key="Client" value="Data Source=MyServer; Initial Catalog=BPOpticalClient; Integrated Security=True"/>
>    <add key="Server" value="Data Source=MyServer; Initial Catalog=BPOptical; Integrated Security=True"/>
>  </appsettings>
></configuration>
>
>How do I read the Client and Server values from this file?
>
>If I try this:
>
>
string clientConnection = ConfigurationSettings.AppSettings["Client"];
>
>I get a warning that this is obsolete and I should use:
>
>
System.Configuration!System.Configuration.ConfigurationManager.AppSettings
>
>Using that gives me an error:
>
>Other examples I've found give various errors.
>
>Anyone have a simple example that will work for me?
>
>update
>
>I found a sample which worked:
>
>
string clientConnection = ConfigurationManager.AppSettings["Client"];
>
>I don't know why this worked now as I had tried it before.

:-}
But since that looks like connection string info I was wondering why you were not using the connectionString section ?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform