ASP.Net SQL Server Express Connection

  1. In Web.Config or App.Config include a connection string:

    <add name="NAMEFORCONNECTION" connectionString="Data Source=SERVER\SQLEXPRESS;Initial Catalog=DATABASENAME;Integrated Security=True" providerName="System.Data.SQLClient"/>
  2. On your Page.aspx, you can refer to the Connection string and include your SQL statement:

    <asp:SqlDataSource ID="sqlConnection1" runat="server" ConnectionString="<%$ ConnectionStrings:NAMEFORCONNECTION %>" SelectCommand="[dbo].[sp_DoStoredProcedure] param1, param2, paramN"/>
  3. Other controls can refer to the SqlDataSource, similarly to this GridView:

    <asp:GridView ID="GridView1" runat="server" DataSourceID="sqlConnection1" AutoGenerateColumns="true" CssClass="Grid" AlternatingRowStyle-CssClass="alt" PagerStyle-CssClass="pgr"></asp:GridView>


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s