retrieve value from Web.Config

Posted on 2007-10-03
Last Modified: 2008-01-09
Using C#, from a WEB.CONFIG, how do I retrieve the value "Server=XYZ;Initial Catalog=ABC;User=MyName;password=pswd;" Here's the WebConfig

<?xml version="1.0"?>
     <configuration xmlns="">
          <add name="MyCustKey" connectionString="Server=XYZ;Initial Catalog=ABC;User=MyName;password=pswd;" providerName="System.Data.SqlClient"/>

Question by:volking
    LVL 9

    Accepted Solution

    you'd do something like this in your code:
    string strConnString = ConfigurationManager.ConnectionStrings["MyCustKey"].ConnectionString;
    LVL 35

    Expert Comment

    are you using 1.1 or 2.0?

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now