title: How to use database connection strings in ASP.NET?
body: <p>I've just started ASP.NET for real, and I was wondering if it is possible to use connection strings from Data Sources instead of hard-coding them. I've added my connection in Data Sources and it works, and I can also drag a table to a page in design mode, but I can't figure out how to access it in code. Here's what I get when I drag it in:</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
      DataSourceID="SqlDataSource1" 
      EmptyDataText="There are no data records to display."&gt;
      &lt;Columns&gt;
          &lt;asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" 
              SortExpression="id" /&gt;
          &lt;asp:BoundField DataField="xxx" HeaderText="xxx" 
              SortExpression="xxx" /&gt;
          &lt;asp:BoundField DataField="xxx" HeaderText="xxx" 
              SortExpression="xxx" /&gt;
      &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="&lt;%$ ConnectionStrings:xxxConnectionString1 %&gt;" 
      ProviderName="&lt;%$ ConnectionStrings:xxxConnectionString1.ProviderName %&gt;" 
      SelectCommand="SELECT xxx FROM xxx"&gt;
  &lt;/asp:SqlDataSource&gt;
  </code></pre>