title: Object reference not set to an instance of an object. - App.config
body: <p>I receiving the error and in the local window I am seeing for both conSettings and connectionString value of null. I am right to say ConfigurationManager is null and I need to create a new object. Maybe I am using Access and perhaps I have missed something in App.config file. Can someone help me on how to solve this problem, please. Thanks in advance.</p>
  
  <p>App.config file...</p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="utf-8" ?&gt;
      &lt;configuration&gt;
      &lt;appSettings&gt;
         &lt;add key="MyDBConnectionString" value="Provider=Microsoft.Jet.OLEDB.4.0;Data 
                     Source=E:\...\Database1.mdb"/&gt;
      &lt;/appSettings&gt;
      &lt;/configuration&gt;
  </code></pre>
  
  <p>Form.cs file...</p>
  
  <pre><code> private void btnShow_Click(object sender, EventArgs e)
      {
          ConnectionStringSettings conSettings = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
  
          string connectionString = ConfigurationManager.ConnectionStrings["MyDBConnectionString"].ConnectionString; // error points here
  
          try
          {
              con = new OleDbConnection(connectionString);
              con.Open();
              cmd = new OleDbCommand("SELECT * FROM Table1", con);
              objReader = cmd.ExecuteReader();
              while (objReader.Read())
              {
                  txtID.Text = ds.Tables[0].Rows[rno][0].ToString();
                  CBAgeGroup.Text = ds.Tables[0].Rows[rno][1].ToString();
                  CBGender.Text = ds.Tables[0].Rows[rno][2].ToString();
                  CBCrimOffen.Text = ds.Tables[0].Rows[rno][3].ToString();
                  if (ds.Tables[0].Rows[rno][4] != System.DBNull.Value)
                  {
                      photo_aray = (byte[])ds.Tables[0].Rows[rno][4];
                      MemoryStream ms = new MemoryStream(photo_aray);
                     pictureBox1.Image = Image.FromStream(ms);
                  }
                  txtCV.Text = ds.Tables[0].Rows[rno][5].ToString();
              }
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message);
          }
          finally
          {
              con.Close();
          }
      }
  </code></pre>
  
  <p>I have been advised to use App.config. </p>
  
  <p>VS 2010 C#
  MS Access 2003 </p>
  
  <p><strong>UPDATE 1</strong>
  My App.config now looks like this...</p>
  
  <pre><code>&lt;configuration&gt;
      &lt;ConnectionString&gt;
          &lt;add key="MyDBConnectionString"   value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Raj\Education\C_Sharp\Test1\Database1.mdb"/&gt;
      &lt;/ConnectionString&gt;
  </code></pre>
  
  <p></p>
  
  <p>I am now receiving error of..."Configuration system failed to initialize". I am looking at it now on Google.</p>
  
  <p><strong>Update 2</strong>
  Tried...</p>
  
  <pre><code>&lt;configuration&gt;
   &lt;connectionStrings&gt;
  &lt;add name="MyDBConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data   
          Source=E:\...\Database1.mdb"/&gt;
    &lt;/connectionStrings&gt;
   &lt;/configuration&gt;
  </code></pre>
  
  <p>Receiving error of "Object reference not set to an instance of an object" Googling again</p>
  
  <p><strong>Update 3</strong></p>
  
  <pre><code>&lt;configuration&gt;
  &lt;connectionStrings&gt;
      &lt;clear /&gt;
      &lt;add name="MyDBConnectionString"
       providerName="System.Data.OleDb" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Source=\Database1.mdb" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p></p>
  
  <p>With the update 3 I am receiving error the same error. I have included the Add reference System. Configuration and I have referenced using System.Configuration;</p>
  
  <p><strong>Conclusion</strong></p>
  
  <p>Perhaps it maybe there is a technical gitch between VS 2010 and Access 2003. I shall not use App.config this time round. I know there will be no problem with SQL Server. So I will leave it that. Thanks Damith and Clint for your time. </p>