title: Getting sql connection string from web.config file
body: <p>I am learning to write into a database from a textbox with the click of a button. I have specified the connection string to my NorthWind database in my <code>web.config</code> file. However I am not able to access the connection string in my code behind. </p>
  
  <p>This is what I have tried.</p>
  
  <pre><code>protected void buttontb_click(object sender, EventArgs e)
  {
      System.Configuration.Configuration rootwebconfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Mohtisham");
      System.Configuration.ConnectionStringSettings constring;
      constring = rootwebconfig.ConnectionStrings.ConnectionStrings["northwindconnect"];
      SqlConnection sql = new SqlConnection(constring);
  
      sql.Open();
      SqlCommand comm = new SqlCommand("Insert into categories (categoryName) values ('" + tb_database.Text + "')", sql);
      comm.ExecuteNonQuery();
      sql.Close();
  }
  </code></pre>
  
  <p>I get a tooltip error for </p>
  
  <pre><code>SqlConnection sql = new SqlConnection(constring);
  </code></pre>
  
  <p>as</p>
  
  <blockquote>
    <p><em>System.data.SqlClient.Sqlconnection.Sqlconnection(string) has some invalid arguments.</em></p>
  </blockquote>
  
  <p>I want to load the connection string from the <code>web.config</code> in <code>constring</code></p>