title: Possible reasons why SqlConnection is NULL
body: <p>Using Visual Studio 2012 which was recently installed but now I can't connect to our SQL Server database.</p>
  
  <p>These are the steps I'm following</p>
  
  <ol>
  <li>create <code>App1.config</code></li>
  <li><p>type this in <code>App1.config</code>:</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8" ?&gt;
   &lt;configuration&gt;
     &lt;connectionStrings&gt;
       &lt;add name ="xxx" connectionString="USER ID=xx;PASSWORD=xx;PERSIST SECURITY INFO=True;Data Source=xx;Initial Catalog=xx" /&gt;
     &lt;/connectionStrings&gt;
   &lt;/configuration&gt;
  </code></pre></li>
  <li><p>Add a reference to the project to <code>System.Configuration</code></p></li>
  <li><p>Create access to namespaces via:</p>
  
  <pre><code> using System.Data.SqlClient;
   using System.Data;
   using System.Configuration;
  </code></pre></li>
  <li><p>implement the following:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Data.SqlClient;
  using System.Data;
  using System.Configuration;
  
  namespace ConsoleApplication10 {
      class Program {
          static void Main(string[] args) {
  
              SqlConnection conn = null;
              conn = new SqlConnection(ConfigurationManager.ConnectionStrings["xxx"].ConnectionString);
  
          }
      }
  }
  </code></pre></li>
  <li><p>I've created a new console app and added the above and I still get an error <code>NullReferenceException was unhandled</code> <code>Object reference not set to an instance of an object.</code> ...</p></li>
  </ol>
  
  <p><img src="https://i.stack.imgur.com/fmZiy.png" alt="enter image description here"></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Via the immediate window I determined that the following is null:</p>
  
  <pre><code>ConfigurationManager.ConnectionStrings["xxx"].ConnectionString
  </code></pre>
  
  <p>If I hard-code the connection string into the constructor for <code>SqlConnection</code> then it connects ok</p>
  
  <p>What am I missing - something really obvious!! Or is this in connection with my new VS ?</p>