How to use reports in ASP web forms app

6 posts, 1 answers
  1. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 10 May Link to this post

    Hi,
    I have been through the docs so many times but I am really struggling to work out how to hang this together.

    What I am hoping to achieve (using an in-app hosted report server as this appears to be the new, recommended method):
    1. Desing reports using the standalone designer on my dev machine, pointing to my local sql server
    2. Deploy the reports to a live client site and view the report in my aspx page, using a db connection configured in the client website.

    What I have done so far:
    1. Created a report on my dev machine which runs just fine in the standalone designer
    2. Add a report viewer page to my app using the .NET template 'Telerik web Forms Report Viewer Form R2 2106'
    3. This gave me a report viewer page, a Reports folder, and a ReportController class.
    4. I dumped my trdp file into the \Reports folder.
    5. I set <ReportSource IdentifierType="UriReportSource" Identifier="Report1.trdp"> in my report viewer page
    6. Running the page, gives an error about database connection being incorrect and a whole bunch of other stuff.

    What I don't get:
    1. How does the report viewer form know where to find the REST service serving the report?
    2. Is the ReportsController.cs all I need or do I need additional stuff to make the REST service work?
    3. How do I switch the report database connection at run time?

    Please help.

  2. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 12 May in reply to Al Link to this post

    Hey Telerik - pls help. I just need some pointers to docs and/or samples that do as explained.
  3. DevCraft banner
  4. Stef
    Admin
    Stef avatar
    3053 posts

    Posted 12 May Link to this post

    Hi Al,

    Based on you description, the only missing step is to add a connection string entry in the web application's web.config file. The connection string entry must have the name of the connection string used in the report.

    On configuring a SqlDataSource component you can save a connection string by name (it will be searched in the application's configuration file), or you can hard-code the connection string (it will be the same always).

    If you have a scenario where the connection string should be changed at run-time, you can switch to an ObjectDataSouce component that allows you to use a custom data retrieval logic. The data access layer can be loaded in the Standalone Report Designer tool by extending the tool's configuration - Extending Report Designer (tutorials at the bottom).


    About using the HTML5 Viewer, please check how it works in the overview help article. In your case you are using the HTML5 WebForms ReportViewer, which is a wrapper of the original JS/CSS/HTML widget. The wrapper renders in browser the Javascript object and registers some scripts at the end of the page (please consider this if you will Ajaxify the page).
    The viewer's properties can be configured from the VS Property grid, where the VS item template provides the viewer with some default settings.

    Regards,
    Stef
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 01 Jun Link to this post

    Hi Stef,

    Thanks for the reply.I managed to get the report working just fine when using an sqlDataSource in the trdp and using the same name of connection string that I have in my web.config. I can't quite wrap my head around having a dynamic connection string though (I am not sure what to do with your comments re: 'Extending Report Designer' and using 'ObjectDataSource' component).

    In my web app I have no connection string at all in web.config. The parameters are stored in a separate file that is read and converted into an sql connection string and an entity framework connection string ie. what I have available is an sql connection object and/or an entity context object. Is there not an easy way that I can just set the datasource of the trdp report to one of these in either my page or in the controller at runtime?

    BTW I think I am using the straight html viewer, not the asp wrapper. Not sure how or why that is.

  6. Answer
    Nasko
    Admin
    Nasko avatar
    909 posts

    Posted 03 Jun Link to this post

    Hello Al,

    The ObjectDataSource will allow you to retrieve data from a custom data retrieval method in your application. You can set the connection string or use your connection object inside this method and retrieve all of the required data, then return it to the report. Please refer to the provided help articles on the topic.

    Regards,
    Nasko
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Al
    Al avatar
    203 posts
    Member since:
    Oct 2006

    Posted 06 Jun in reply to Nasko Link to this post

    Hi Nasko,

    Thanks, I have managed to extend the designer to use my custom dll and can successfully preview the report in the designer (custom dll is in the same folder as the report designer exe).

    I copied the tdrp into the /Reports folder of my site and set the ReportViewer's 'Identifier' property to the report name - it seems to find the report ok as it runs. Initially I saw no data but when I copied my custom dll into the website's 'bin' dir then all worked just fine.

Back to Top
DevCraft banner