title: Not able to establish connection via SqlHelper class
body: <pre><code>   string strCon =
             ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
  
  
             Company.Common.SqlHelper.Connect = strCon;
  </code></pre>
  
  <p>Getting this exception someone please help</p>
  
  <pre><code>"The type initializer for 'Company.Common.SqlHelper' threw an exception."}
  </code></pre>
  
  <hr>
  
  <pre><code>  /// &lt;summary&gt;
  /// The SqlHelper class is intended to encapsulate high performance, scalable best practices for 
  /// common uses of SqlClient
  /// &lt;/summary&gt;
  public sealed class SqlHelper
  {
      public void MessageBox(string message, Control ControlID)
      {
  
          //tmp = "&lt;script language='javascript'&gt;";
          string tmp = "alert('" + message + "');";
          //tmp += "&lt;/script&gt;";
          //ScriptManager.RegisterStartupScript(this, this.GetType(), "tmp", tmp, true); 
          //string CloseWindow;
          //CloseWindow = "alert('Hello World')";
          ScriptManager.RegisterStartupScript(ControlID, ControlID.GetType(), "tmp", tmp, true);
          // Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MyScript", tmp);
      }
      public static string Connect = ConfigurationManager.ConnectionStrings["Constr"].ConnectionString.ToString();
      #region private utility methods &amp; constructors
  
      // Since this class provides only static methods, make the default constructor private to prevent 
      // instances from being created with "new SqlHelper()"
      private SqlHelper() { }
  
      /// &lt;summary&gt;
      /// This method is used to attach array of SqlParameters to a SqlCommand.
      /// 
      /// This method will assign a value of DbNull to any parameter with a direction of
      /// InputOutput and a value of null.  
      /// 
      /// This behavior will prevent default values from being used, but
      /// this will be the less common case than an intended pure output parameter (derived as InputOutput)
      /// where the user provided no input value.
      /// &lt;/summary&gt;
      /// &lt;param name="command"&gt;The command to which the parameters will be added&lt;/param&gt;
      /// &lt;param name="commandParameters"&gt;An array of SqlParameters to be added to command&lt;/param&gt;
      private static void AttachParameters(SqlCommand command, SqlParameter[] commandParameters)
      {
          if (command == null) throw new ArgumentNullException("command");
          if (commandParameters != null)
          {
              foreach (SqlParameter p in commandParameters)
              {
                  if (p != null)
                  {
                      // Check for derived output value with no value assigned
                      if ((p.Direction == ParameterDirection.InputOutput ||
                          p.Direction == ParameterDirection.Input) &amp;&amp;
                          (p.Value == null))
                      {
                          p.Value = DBNull.Value;
                      }
                      command.Parameters.Add(p);
                  }
              }
          }
      }
  </code></pre>
  
  <p>}</p>