SearchForKnowledge
SearchForKnowledge

Reputation: 3751

How to use appSettings key in SqlDataSource

Web.config:

<appSettings file="Application.config">
        <add key="stringC" value="Data Source=svr1;Initial Catalog=myDB;Integrated Security=FALSE;user=user2;pwd=@#$123pop;" />
</appSettings>

ASP.net:

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ {HOW TO USE THE APP SETTINGS KEY HERE} %>"
    SelectCommand="SELECT [au_id], [au_lname], [au_fname], [state] FROM [authors]" />

How do I replace the {HOW TO USE THE APP SETTINGS KEY HERE} with the application key.

Upvotes: 1

Views: 827

Answers (2)

Izzy
Izzy

Reputation: 6866

In your aspx you want the following

ConnectionString="<%$ appSettings:stringC %>"

Upvotes: 2

hutchonoid
hutchonoid

Reputation: 33306

You could use <%$ ConfigurationSettings.AppSettings["stringC"] %>.

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConfigurationSettings.AppSettings["stringC"] %>"
    SelectCommand="SELECT [au_id], [au_lname], [au_fname], [state] FROM [authors]" />

Upvotes: 3

Related Questions