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?

1 Answer 1

5

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>
Sign up to request clarification or add additional context in comments.

1 Comment

Hmmm... I swore I already tried that exact string but just in case, I tried it again and it worked great. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.