Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reading values from app.config
Message
De
01/04/2013 11:49:08
 
 
À
01/04/2013 10:51:19
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:
01569663
Vues:
37
J'aime (1)
>>:-}
>>But since that looks like connection string info I was wondering why you were not using the connectionString section ?
>
>I just used the example I found on-line. Does the app.config have pre-set sections? I didn't know that, I thought I could use anything I wanted.


Hi Frank,

You can put connection strings in the appSettings section and it works fine. But, there is also a connectionStrings section (as Viv says), and you can also use that for connection strings. We do it both ways, actually.

This is what it looks like:

The section in the app.config:
  <connectionStrings>
    <add name="QueueLocal" connectionString="server=(local);uid=sa;pwd=MyPassword;database=queue"/>
    <add name="QueueAzure" connectionString="Server=tcp:MyAzure;User ID=MyId;pwd=MyPassword;Database=queue;Trusted_Connection=False;Encrypt=True"/>
  </connectionStrings>
To access the connection string in C#:
string connString = ConfigurationManager.ConnectionStrings["QueueLocal"];
~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform