none
RDLC Local report generation stops prematurely on SetParameter without logging an error RRS feed

  • Question

  • I have a MVC Controller method that writes the results of an RDLC report to a file. This works fine on my local machine but when it is published to production, it stops execution on the setparameters line and does not trigger an exception. Any clues would be appreciated.

    IIS on my local machine and on the server are the same version. I have checked the event log and nothing was logged there either.

        public JsonResult GenerateSignInSheet(string id)
        {
            try
            {
                string pgmid = id;
                string strProgDate = "";
                DateTime? dtProgDate = null;
                Program prog = db.Programs.SingleOrDefault(p => p.ProgramID == pgmid);
                if (prog != null)
                    dtProgDate = prog.ProgDate;
                if (dtProgDate != null)
                    strProgDate = String.Format("{0:d}", dtProgDate);
    
                string strProgLoc = string.Empty;
                var locInfo = this.dc.usp_ProgramLocSiteInfo(id).SingleOrDefault();
                if (locInfo != null) strProgLoc = locInfo.VendorOrHost ?? string.Empty;
    
                //Rep information
                string strRepName = string.Empty;
    
                LocalReport localReport = new LocalReport();
    
                // the following 2 lines will allow globals to work - MS gotcha
                System.Security.PermissionSet sec = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
                localReport.SetBasePermissionsForSandboxAppDomain(sec);
    
                localReport.ReportPath = Server.MapPath("~/Content/Reports/RptSignInSheetPrefilled.rdlc");
                var sourceList = dc.GetRSVPListForSignin(pgmid).ToList();
                ReportDataSource reportDataSource = new ReportDataSource("DataSetRSVPList", sourceList);
                ReportParameter p1 = new ReportParameter("ProgramID", pgmid);
                ReportParameter p2 = new ReportParameter("ProgDate", strProgDate);
                ReportParameter p3 = new ReportParameter("LocName", strProgLoc);
                ReportParameter p4 = new ReportParameter("RepName", strRepName);
    
                localReport.SetParameters(new ReportParameterCollection { p1, p2, p3, p4 });
                localReport.DataSources.Add(reportDataSource);
    
                //string reportType = "PDF";
                string mimeType;
                string encoding;
                string fileNameExtension;
    
                //The DeviceInfo settings should be changed based on the reportType
                //http://msdn2.microsoft.com/en-us/library/ms155397.aspx
    
                string deviceInfo =
    
                "<DeviceInfo>" +
                "  <OutputFormat>PDF</OutputFormat>" +
                "  <PageWidth>11in</PageWidth>" +
                "  <PageHeight>8.5in</PageHeight>" +
                "  <MarginTop>0.5in</MarginTop>" +
                "  <MarginLeft>0.5in</MarginLeft>" +
                "  <MarginRight>0.5in</MarginRight>" +
                "  <MarginBottom>0.5in</MarginBottom>" +
                "</DeviceInfo>";
    
                Warning[] warnings;
                string[] streams;
                byte[] renderedBytes;
    
                //Render the report
                renderedBytes = localReport.Render(
                    "PDF",
                    deviceInfo,
                    out mimeType,
                    out encoding,
                    out fileNameExtension,
                    out streams,
                    out warnings);
    
                string strPDFOutputPath = System.Configuration.ConfigurationManager.AppSettings["PDFDocumentsPath"].ToString();
                string strPDFFilename = strPDFOutputPath + id.Replace("-", string.Empty) + ".pdf";
    
                System.IO.FileStream fs = new System.IO.FileStream(strPDFFilename, System.IO.FileMode.Create);
                fs.Write(renderedBytes, 0, renderedBytes.Length);
                fs.Close();
                fs.Dispose();
    
    
                //var theFile = File(renderedBytes, mimeType);
    
                return Json(new { File = strPDFFilename });
    
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return Json(new { File = "" });
            }
        }

    • Moved by Challen FuModerator Monday, May 7, 2012 5:21 AM better support (From:SQL Server Reporting Services)
    Thursday, May 3, 2012 7:05 PM

All replies

  • Hi Chris,

    This question is more relevant to RDLC report rather than reporting services, so I move it to this queue to receive more specific support, thanks for your understanding. Here I also give you a advices, please use other browser to check whether this issue is relevant to browser.

    Thanks,


    Challen Fu

    TechNet Community Support

    Monday, May 7, 2012 5:24 AM
    Moderator
  • FYI - The code above does NOT use the viewer. It is supposed to write the report to a file but it never seems to get that far.
    Monday, May 7, 2012 12:54 PM
  • I'm running into almost the exact same issue. What's going on (for me at least) is that when you're publishing, the RDLC files are being put in the /bin directory.

    For instance, in development my report files are being created in the /Reports directory. When I publish, they're being put in /bin/Reports instead of just /Reports.

    That's why you're not getting any errors--because the file doesn't exist, so the server just treats it like a 404 (I'm assuming, may be wrong on this).

    Anyway, if you just move the RDLC files into the directory you're expecting on the server (in your case, ~/Content/Reports/RptSignInSheetPrefilled.rdlc) then it'll just work. I'm still trying to figure out why they're not being moved automatically, so if anyone has a suggestion, it'd be much appreciated.


    Thursday, June 21, 2012 7:52 PM