none
Dynamically Filling 2010 Web Form ReportViewer with RDLC and Entity Framework RRS feed

  • Question

  • Hi all,

    I've got a bunch of reports to build using VS 2010 for a website.  The site is generally built using Entity Framework, so I'm trying to design all the reports RDLCs (each with their own dataset) - and then fill each report dynamically in a webform at runtime.  This way, I can just build one page, and update the RDLC and data set from entity framework. The user should then be able to select the report they want, click refresh and have the right data displayed.

    Unfortunately, I'm finding it very difficult to get the reportviewer to work in the webform.  I've looked at a few examples from the web (although most seem to be built using VS2008). An example is this one - http://weblogs.asp.net/rajbk/archive/2010/05/09/creating-a-asp-net-interactive-report-using-visual-studio-2010-part-3.aspx

    I've got a sample RDLC, I've set the LocalReport / ReportPath "hardcoded for the time being).  I then have this code in the Page Load event (I've read articles to resolve the initial dataset error I had that was generated as a result of the dataset built using the designer):

      protected void Page_Load(object sender, EventArgs e)
    
      {
    
    
    
       using (FAReports fadb = new FAReports())
    
       {
    
        var rep = fadb.rpGetSalesByQuarter().ToList();
        var rs = new ReportDataSource("SalesByQuarter", rep);
    
        rvRF.LocalReport.DataSources.Add(rs);
        rvRF.LocalReport.Refresh();
       }
    
      }
    
    

    Here is the ReportView snippet:

    <rsweb:ReportViewer ID="rvRF" runat="server" Font-Names="Verdana" Font-Size="8pt" InteractiveDeviceInfos="(Collection)" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" ShowBackButton="False" ShowExportControls="False" ShowFindControls="False" ShowPageNavigationControls="False" ShowPrintButton="False" ShowZoomControl="False">
       <LocalReport ReportPath="secure\reports\SalesByQuarter.rdlc">
       </LocalReport>
      </rsweb:ReportViewer>
      <asp:ObjectDataSource ID="odsReports" runat="server" SelectMethod="rpGetSalesByQuarter" TypeName="SLMonte.Reports.FAReports">
      </asp:ObjectDataSource>
    

    Code seems simple enough. The errors I'm getting at the moment are:

    • When the report attempts to load after the Refresh call previously, it hangs on the Loading screen for some time. After approximately 30 secs to 1 min, I get the error below
    • Error: Sys.WebForms.PageRequestManagerServerErrorException: Timeout expired.  The timeout period elapsed prior to obtaining a connection from the pool.  This may have occurred because all pooled connections were in use and max pool size was reached.

     Does anyone know why this is happening?  Alternatively, does someone have some simply working Entity Framework code that I can run to set how this can be done?

    thanks

     

    • Edited by ossent Monday, February 14, 2011 12:21 AM Formatting improvements
    Monday, February 14, 2011 12:11 AM

Answers

  •       //// Reset the viewer in case we're switching from a drillthrough report (not at the root of the drillthrough hierarchy). 
          //// You can also get back to the root by repeatedly calling ReportViewer.PerformBack(). However, ReportViewer.Reset() will
          //// reset all other settings as well, so we can work with a clean ReportViewer object.
          ReportViewer1.Reset();
    
          //// Set the processing mode
          ReportViewer1.ProcessingMode = ProcessingMode.Local;
    
          //// Set the report definition
          ReportViewer1.LocalReport.ReportPath = Server.MapPath(String.Format("{0}.rdlc", ddlReports.SelectedValue));			
    			ReportDataSource rds = null;
    			
    			// Get Entity Data
    			sales = LoadReports(GetSalesByQuarter);
    			rds = new ReportDataSource(ReportViewer1.LocalReport.GetDataSourceNames()[0], sales);
    
          // check there is a valid report
          if (rds.Equals(null) == false)
            ReportViewer1.LocalReport.DataSources.Add(rds);
    

    In case anybody else has the same problem - this code snippet works for me. You may need to amend to get it to build - but hopefully you understand what I'm trying to do.

    thanks

    • Marked as answer by ossent Tuesday, February 15, 2011 12:46 PM
    Tuesday, February 15, 2011 12:45 PM

All replies

  • Update: for anyone finding similar issues, I've found some VS 2010 samples here: http://code.msdn.microsoft.com/reportviewer.

    One specific example (SupplyingData) looks like a good fit for what I'd like to do. I'll investigate further. 

    thanks

    • Marked as answer by ossent Tuesday, February 15, 2011 12:44 PM
    • Unmarked as answer by ossent Tuesday, February 15, 2011 12:44 PM
    • Marked as answer by ossent Tuesday, February 15, 2011 12:46 PM
    • Unmarked as answer by ossent Tuesday, February 15, 2011 12:46 PM
    Monday, February 14, 2011 9:50 AM
  •       //// Reset the viewer in case we're switching from a drillthrough report (not at the root of the drillthrough hierarchy). 
          //// You can also get back to the root by repeatedly calling ReportViewer.PerformBack(). However, ReportViewer.Reset() will
          //// reset all other settings as well, so we can work with a clean ReportViewer object.
          ReportViewer1.Reset();
    
          //// Set the processing mode
          ReportViewer1.ProcessingMode = ProcessingMode.Local;
    
          //// Set the report definition
          ReportViewer1.LocalReport.ReportPath = Server.MapPath(String.Format("{0}.rdlc", ddlReports.SelectedValue));			
    			ReportDataSource rds = null;
    			
    			// Get Entity Data
    			sales = LoadReports(GetSalesByQuarter);
    			rds = new ReportDataSource(ReportViewer1.LocalReport.GetDataSourceNames()[0], sales);
    
          // check there is a valid report
          if (rds.Equals(null) == false)
            ReportViewer1.LocalReport.DataSources.Add(rds);
    

    In case anybody else has the same problem - this code snippet works for me. You may need to amend to get it to build - but hopefully you understand what I'm trying to do.

    thanks

    • Marked as answer by ossent Tuesday, February 15, 2011 12:46 PM
    Tuesday, February 15, 2011 12:45 PM
  • You may want to take a look at www.rptgen.com

    Thanks

    Sunday, July 3, 2011 11:27 PM