title: SQL Server cnnection error: Unhandled exception
body: <p>Reference: <a href="https://stackoverflow.com/questions/8476103/accessing-database-connection-string-using-app-config-in-c-sharp-winform">Accessing database connection string using app.config in C# winform</a>
  I am trying to connect my C# file.cs with App.config but I am getting an error</p>
  
  <blockquote>
    <p>Unhanded exception System.NullReferenceException: Object reference not set to an instance of an object</p>
  </blockquote>
  
  <p>Here is what I am doing.</p>
  
  <p>App.config</p>
  
  <pre><code>&lt;appSettings&gt;
      &lt;add key="SQLConn" value="Data Source=dbw.xyz.abc.com(just an example);
         Initial catalog=database_name;Integrated Security=True;
         User ID=username;Password=password"/&gt; 
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>SqlConnection SQLConn = new SqlConnection();
  SQLConn.ConnectionString = 
         ConfigurationManager.ConnectionStrings["SQLConn"].ConnectionString;
  try
  {
       SQLConn.Open();
  }
  catch (Exception e)
  {
      Console.WriteLine("Program aborted: " + e);
  }
  finally
  {
      if (SQLConn.State == ConnectionState.Open)
          SQLConn.Close();
  }
  </code></pre>