in my C# code, I use a connection string like this:
connection = new SqlConnection(ConfigurationManager.AppSettings["myconnectionstring"])
which works fine.
I’m now trying to use the <asp:SqlDataSource control, but I can’t seem to use the above connection string in the control like this:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConfigurationManager.AppSettings["myconnectionstring"] %>"
SelectCommand="SELECT * from table1"></asp:SqlDataSource>
I get an error saying:
Parser Error Message: The server tag is not well formed.
What am I doing wrong?
it is not code you run there but a placeholder: that basically tells the DataSource ‘look in the config file for a configuration block called ConnectionStrings and if you find it take the value from the element with the key myconnectionstring’
remember to add your connectionstring the app.config section ConnectionStrings,
specially because you want to keep them safe