title: TypeInitializationException in C#
body: <p>I'm going to create a student information system based on a tutorial. 
  As soon as a user wants to add a new student to the database the following exception occurs. </p>
  
  <p>I tried to learn something about TypeInitializationException and I understand a little by its name.. but I can't get it totally. Besides, the exception is absent from the tutorial I'm following.. I'm new in this type of OOP programming and handling errors. I included my database connection and database access class below..</p>
  
  <p><img src="https://i.stack.imgur.com/Wn4ia.png" alt="exception pic"></p>
  
  <p><strong>My <code>DB_Connection</code> class</strong></p>
  
  <pre><code>using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Data;
  using System.Data.SqlClient;
  using System.Configuration;
  
  namespace studentInformationSystem
  {
      class DB_Connection
      {
          public static SqlConnection NewConnection;
          public static string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
  
          public static SqlConnection getConnection()
          {
              NewConnection = new SqlConnection(ConString);
              return NewConnection;
          }
      }
  }
  </code></pre>
  
  <p><strong>My <code>DB_Access</code> class</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Data;
  using System.Data.SqlClient;
  
  namespace studentInformationSystem
  {
      class DB_Access
      {
          public SqlConnection conn;
          public DB_Access()
          {
              conn = DB_Connection.getConnection();
          }
  
          public void AddStudent(string regNo, string fName, string lName, string phoneNumber)
          {
              if(conn.State.ToString() == "Closed")
              {
                  conn.Open();
              }
  
              SqlCommand newCommand = conn.CreateCommand();
              newCommand.Connection = conn; //why we use it..???
              newCommand.CommandType = CommandType.Text;
              newCommand.CommandText = "insert into student values('" + regNo + "','" + fName + "','" + lName + "','" + phoneNumber + "')";
              newCommand.ExecuteNonQuery();
  
          }
      }
  }
  </code></pre>
  
  <p>here is my connectionString</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;startup&gt; 
          &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
      &lt;/startup&gt;
  
    &lt;configSections&gt;
  
      &lt;connectionStrings&gt;
        &lt;add name="ConString" connectionString="Data Source=SADID-PC\SQLEXPRESS;Initial Catalog=Test1;Integrated Security=True" 
             providerName="System.Data.sqlClient" /&gt;  
      &lt;/connectionStrings&gt;
  
    &lt;/configSections&gt;
  
  &lt;/configuration&gt;
  </code></pre>