In my .aspx page VS2008 C# ASP.NET I have this line:
-----------
<asp:SqlDataSource ID="mySqlDataSourceID" runat="server"
ConnectionString="<%$ ConnectionStrings:myConnectionString1 %>"
onselecting="mysomething"
ProviderName="<%$ ConnectionStrings:myConnectionString1.ProviderName %>"
SelectCommand="SELECT * from MyTab">
</asp:SqlDataSource>
-----------
The web.config has:
<configuration>
<connectionStrings>
<add name="myConnectionString1" connectionString="DATA SOURCE=mySOMETHING1;PASSWORD=myPwd;PERSIST SECURITY INFO=True;USER ID=myID"
providerName="Oracle.DataAccess.Client" />
</connectionStrings>
</configuration>
------
Above works.
But I need to get rid of "myConnectionString1" under <connectionStrings> in the web.config file.
Instead I need to use the similar stuf under: <appSettings> in the web.config file.
The current contenct in web.config ther is:
<appSettings>
<add key="myKey1" value="Data Source=mySOMETHING1;Persist Security Info=True;User ID=myID;Password=myPwd;"/>
</appSettings>
The value of "myKey1" in the <appSettings> is same as the myConnectionString1under <myConnectionString>.
How could I use "myKey1" of <appSettings> above instead of "myConnectionString1" in <connectionStrings> for the SqlDataSource ID "mySqlDataSourceID" ?
In my .aspx.page?
I tried:
<asp:SqlDataSource ID="mySqlDataSourceID" runat="server"
ConnectionString="<%$ AppSettings["myKey1"] %>"
onselecting="mysomething"
ProviderName="Oracle.DataAccess.Client"
SelectCommand="SELECT * from MyTab">
</asp:SqlDataSource>
But It shows syntax error for the line:
ConnectionString="<%$ AppSettings["myKey1"] %>"
How to fix?