Home > DeveloperSection > Forums > How to get connection string from app.config file in VC#.
James Smith

Total Post:48

Points:336
Posted on    July-30-2011 4:55 AM

 C# C# 
Ratings:


 2 Reply(s)
 4674  View(s)
Rate this:

Hi,

I would like to access connection string from app.config file but am not able to perform it. I am using C# as a programing language and visual studio 2010 IDE on windows 7 64 bit plateform.

Help needed.

Thanks.




Awadhendra Tiwari

Total Post:126

Points:882
Posted on    July-30-2011 5:06 AM

Hi james,

You can use following line of code to access connection string from app.config file.

string cs = System.Configuration.ConfigurationSettings.AppSettings["cs"].ToString();
For this app.config file.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add value="DataSource=a;User Id=ccc;" key="cs"/>
  </appSettings>
</configuration>
Thanks.

Don't want to miss updates? Please click the below button!

Follow MindStick