views:

19

answers:

1

I want to be able to quickly create some simple ASP.NET reports that don't have a code behind file. Each report will be an aspx file that may have multiple SqlDataSource controls on it. I want to be able to use the <%$ ConnectionStrings:MyTag %> syntax to set the connection string but, the application we're using has the actual connection string in a separate config file that is referenced in the web.config by using configSource="App_Data\database.config".

In code behind, I can programmatically access the ConnectionString using: ConfigurationManager.ConnectionStrings["AbleCommerce"].ConnectionString

But how do we set the connection string without using a code behind?

A: 

You've aluded to the answer in your question, if your connection string is defined in an external file I'm guessing the contents of that file will look like:

<connectionStrings>
    <add name="AbleCommerce" 
        connectionString="..." 
        providerName="System.Data.SqlClient" />
</connectionStrings>

You would reference this in your aspx page by using

<asp:sqldatasource id="SqlDataSource1" runat="server" 
    connectionstring="<%$ ConnectionStrings:AbleCommerce %>" 
    selectcommand="SELECT * FROM [tProducts]"></asp:sqldatasource>
Naeem Sarfraz
Hmmm... I swore I already tried that exact string but just in case, I tried it again and it worked great. Thanks!
EfficionDave