How to get connection string from app.config file in VC#.

Total Post:48

Points:336
C# 
C#
 5375  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. 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.

      Modified On Mar-29-2018 04:19:08 AM

Answer

NEWSLETTER

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