HOW TO GET CONNECTION STRING FROM APP.CONFIG FILE IN VC#.

James Smith

Total Post:48

Points:336
Posted by  James Smith
C# 
C#
 4982  View(s)
Ratings:
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.

  1. Awadhendra Tiwari

    Post:126

    Points:882
    Re: How to get connection string from app.config file in VC#.

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!