Example of a Connection String
<connectionStrings>
<add name="CMSConnectionString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|main.mdf;User Instance=true"providerName="System.Data.SqlClient"/>
</connectionStrings>
You can reference this directly from codebehind using:[C#]
string ConnectionStringFromWebConfig= ConfigurationManager.ConnectionStrings["CMSConnectionString"].ConnectionString;
stringsqlConnectString = @"" + ConnectionStringFromWebConfig + "";
SqlConnectionsqlConnection = newSqlConnection(sqlConnectString);
Namespace required
usingSystem.Configuration;
For ascx or aspx file
You can reference this declaratively within the ConnectionString property of a SqlDataSource:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MainConnStr %>"
SelectCommand="SELECT [au_id], [au_lname], [au_fname], [state] FROM [authors]" />