title: Calling a stored procedure with asp.net
body: <p>If I have a connection string defined in my web.config file, how do I create a connection to the SQL db from <strong>C#</strong> code (sorry forgot to specify) and then call a stored procedure. I would then like to eventually use this data in some way as my DataSource for a GridView. </p>
  
  <p>Here is how the connection string is defined in the web.config:</p>
  
  <pre><code>&lt;connectionStrings&gt;
   &lt;add name="db.Name" connectionString="Data Source=db;Initial Catalog=dbCat;User ID=userId;Password=userPass;" providerName="System.Data.SqlClient" /&gt;
   &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>The db server is a Microsoft SQL server. </p>
  
  <p>Here is what I was looking for: </p>
  
  <pre><code>ConnectionStringSettings conSet = ConfigurationManager.ConnectionStrings["db.Name"];
  SqlConnection con = new SqlConnection(conSet.ConnectionString);
  </code></pre>
  
  <p>The code to get the data is fairly trivial. I was more interested in accessing it from a connectionString variable in the web.config file.</p>