title: Fetching connection string from appconfig file in c#
body: <p>I have the following connection string declared in my <code>app.config</code> file:</p>
  
  <pre><code>  &lt;connectionStrings&gt;
      &lt;add name="SqlConnectionString" connectionString="Data Source=xxx.xx.xx.xx;Initial Catalog=xxxxx;User Id=xx;Password=xxx;" providerName="System.Data.SqlClient" /&gt;
    &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>When I try to fetch this connection string using the following C# code snippet, I get the value <code>null</code>. I am not able to obtain the connection string. Is there anything wrong in the syntax?</p>
  
  <p>First attempt:</p>
  
  <pre><code>var settings = ConfigurationManager.ConnectionStrings["SqlConnectionString"];
  string result = settings.ConnectionString;
  </code></pre>
  
  <p>Second attempt:</p>
  
  <pre><code>string result = ConfigurationSettings.AppSettings["SqlConnectionString"];
  </code></pre>