none
2008 Web Report Viewer rsReportParameterValueNotSet error during Render RRS feed

  • Question

  • <input type="hidden" value="11423100" />

    Im using SSRS 2008 (NOT R2) I'm using the Web Viewer Control (2010). I'm calling the

    I'm calling the web service and asking for PDF output from 2 separate reports, and then knitting the results together using iTextSharp.

    Each of the reports has 3 parameters: an integer PartyID, an integer Contract, and a string FinancialPeriod.

    Out of nowhere, and without changing any code, I'm getting the following error when I call render on the first report (the line after the comment: // Grab the PDF stream from the first report (portrait) )

    I look at the list of parameters that I'm sending into and they are all there (esp PartyID)

    "This report requires a default or user-defined value for the report parameter 'PartyID'. To run or subscribe to this report, you must provide a parameter value. (rsReportParameterValueNotSet)"

    Any ideas?

    Here's the class I'm using:

    using System;
    using
    System.Collections.Generic;
    using
    System.Linq;
    using
    System.Web;
    using
    Microsoft.Reporting.WebForms;
    using
    System.IO;
    using iTextSharp
    .text;
    using iTextSharp
    .text.pdf;
    using
    System.Configuration;
    using
    System.Security.Principal;
    using
    System.Net;

        namespace
    InvoiceLauncher
       
    {
           
    public enum InvoiceType
           
    {
               
    Standard,
                MV
           
    }

           
    public class SSRSInvoiceLauncher
           
    {
               
    public InvoiceType InvoiceType { get; set; }
               
    public int PartyID { get; set; }
               
    public int ContractID { get; set; }
               
    public string FinancialPeriod { get; set; }
               
    public string ErrorMessage { get; set; }

               
    private string firstReportPath = "";
               
    private string secondReportPath ="" ;
               
    private string ReportServerURL { get; set; }

               
    private Dictionary<string, string> monthAbbreviations =
                   
    new Dictionary<string, string>
                   
    {
                       
    {"JAN","01"},
                       
    {"FEB","02"},
                       
    {"MAR","03"},
                       
    {"APR","04"},
                       
    {"MAY","05"},
                       
    {"JUN","06"},
                       
    {"JUL","07"},
                       
    {"AUG","08"},
                       
    {"SEP","09"},
                       
    {"OCT","10"},
                       
    {"NOV","11"},
                       
    {"DEV","12"}
                   
    };

               
    public bool Generate(out MemoryStream generatedPDFStream)
               
    {
                   
    ErrorMessage = "";
                   
    ReportServerURL = GetReportServerURL();

                    generatedPDFStream
    = new MemoryStream();

                   
    if (!ValidParmeters())
                   
    {
                       
    ErrorMessage = "Invalid parameters";
                       
    return false ;
                   
    }

                    firstReportPath
    = GetFirstReportPath();
                    secondReportPath
    = GetSecondReportPath();

                   
    List<ReportParameter> paramList = new List<ReportParameter>();

                    paramList
    .Add(new ReportParameter("PartyID", PartyID.ToString()));
                    paramList
    .Add(new ReportParameter("Contract", ContractID.ToString()));
                    paramList
    .Add(new ReportParameter("FinancialPeriod", FinancialPeriod));

                   
    string outputtype = "PDF";
                   
    string mimeType = "";
                   
    byte[] pdfFirstReportBinary;
                   
    byte[] pdfSecondReportBinary;
                   
    string encoding = "";
                   
    string[] streams;
                   
    Microsoft.Reporting.WebForms.Warning[] warnings;

                   
    ReportViewer viewer = new ReportViewer();

                    viewer
    .ServerReport.ReportServerUrl = new Uri(ReportServerURL);
                    viewer
    .ServerReport.ReportServerCredentials = new MyReportServerCredentials();

                    viewer
    .ServerReport.ReportPath = firstReportPath;

                    viewer
    .ServerReport.SetParameters(paramList);

                   
    // Grab the PDF stream from the first report (portrait)

                   
    // this line fails
                    pdfFirstReportBinary
    = viewer.ServerReport.Render(
                                                        outputtype
    ,
                                                       
    "",
                                                       
    out mimeType,
                                                       
    out encoding,
                                                       
    out outputtype,
                                                       
    out streams,
                                                       
    out warnings);

                   
    /*
                    using (FileStream xx = File.Create(@"c:\mydevelopment\test.pdf"))
                    {
                        xx.Write(pdfFirstReportBinary, 0, pdfFirstReportBinary.Length);
                    }
                     */


                   
    // Grab the PDF file from the second report (landscape)

                    viewer
    .ServerReport.ReportPath = secondReportPath;

                    viewer
    .ServerReport.SetParameters(paramList);          

                    pdfSecondReportBinary
    = viewer.ServerReport.Render(
                                            outputtype
    ,
                                           
    @"",
                                           
    out mimeType,
                                           
    out encoding,
                                           
    out outputtype,
                                           
    out streams,
                                           
    out warnings);

                   
    /*
                    using (FileStream xx = File.Create(@"c:\mydevelopment\test2.pdf"))
                    {
                        xx.Write(pdfSecondReportBinary, 0, pdfSecondReportBinary.Length);
                    }
                    */


                   
    // Knit them together into one pdf in a stream

                   
    Document doc = new Document();
                   
    try
                   
    {
                       
    PdfCopy copy = new PdfCopy(doc, generatedPDFStream);

                        doc
    .Open();

                       
    AddPDF(doc, copy, pdfFirstReportBinary);
                       
    AddPDF(doc, copy, pdfSecondReportBinary);

                        doc
    .Close();

                   
    }
                   
    catch (Exception ex)
                   
    {
                       
    ErrorMessage = ex.InnerException.Message;
                        generatedPDFStream
    = null;
                   
    }

                   
    return String.IsNullOrEmpty(ErrorMessage);
               
    }

               
    private string GetFirstReportPath()
               
    {
                   
    AppSettingsReader reader = new AppSettingsReader();
                   
    string retval = "";

                   
    switch (InvoiceType)
                   
    {
                       
    case InvoiceType.Standard:
                            retval
    = "/" + reader.GetValue("StandardInvoiceReportFolder",typeof(string)) +
                                    
    "/" + reader.GetValue("StandardInvoicePortraitReportName",typeof(string)) ;
                           
    break;
                       
    case InvoiceType.MV:
                            retval
    = "/" + reader.GetValue("MVInvoiceReportFolder",typeof(string)) +
                                    
    "/" + reader.GetValue("MVInvoicePortraitReportName",typeof(string)) ;
                           
    break;
                       
    default:
                            retval
    = "";
                           
    break;
                   
    }

                   
    return retval;
               
    }

               
    private string GetSecondReportPath()
               
    {
                   
    AppSettingsReader reader = new AppSettingsReader();
                   
    string retval = "";

                   
    switch (InvoiceType)
                   
    {
                       
    case InvoiceType.Standard:
                            retval
    = "/" + reader.GetValue("StandardInvoiceReportFolder",typeof(string)) +
                                    
    "/" + reader.GetValue("StandardInvoiceLandscapeReportName",typeof(string)) ;
                           
    break;
                       
    case InvoiceType.MV:
                            retval
    = "/" + reader.GetValue("MVInvoiceReportFolder",typeof(string)) +
                                    
    "/" + reader.GetValue("MVInvoiceLandscapeReportName",typeof(string)) ;
                           
    break;
                       
    default:
                            retval
    = "";
                           
    break;
                   
    }

                   
    return retval;
               
    }

               
    private string GetReportServerURL()
               
    {
                   
    AppSettingsReader reader = new AppSettingsReader();
                   
    string retval= ""+reader.GetValue("ReportServerURL", typeof(string));
                   
    return retval;
               
    }

               
    private bool ValidParmeters()
               
    {
                   
    return !String.IsNullOrEmpty(ReportServerURL) &&
                          
    PartyID > 0 &&
                          
    ContractID > 0 &&
                          
    ValidFinancialPeriodName();
               
    }

               
    private bool ValidFinancialPeriodName()
               
    {
                   
    string month = FinancialPeriod.Substring(0, 3).ToUpper();

                    bool validPeriodYear
    = true;

                   
    string year = FinancialPeriod.Substring(4);

                   
    foreach (char ch in year)
                   
    {
                       
    if (!Char.IsDigit(ch))
                       
    {
                            validPeriodYear
    = false;
                           
    break;
                       
    }
                   
    }

                    validPeriodYear
    = validPeriodYear && year.Length == 4;

                   
    return monthAbbreviations.ContainsKey(month) &&
                          
    FinancialPeriod.Substring(3, 1) == "-" &&
                           validPeriodYear
    ;
               
    }

               
    private void AddPDF(Document doc, PdfCopy copy, byte[] binary)
               
    {
                   
    PdfReader reader = new PdfReader(binary);

                   
    for (int pageNumber = 0; pageNumber < reader.NumberOfPages; )
                   
    {
                       
    ++pageNumber;
                       
    float width = reader.GetPageSize(pageNumber).Width;
                       
    float height = reader.GetPageSize(pageNumber).Height;
                       
    if (width > height)
                       
    {
                           
    PdfDictionary pageDict = reader.GetPageN(pageNumber);
                            pageDict
    .Put(PdfName.ROTATE, new PdfNumber(90));                    
                       
    }
                        copy
    .AddPage(copy.GetImportedPage(reader, pageNumber));
                   
    }
               
    }
           
    }

           
    [Serializable]
           
    public sealed class MyReportServerCredentials :
               
    IReportServerCredentials
           
    {
               
    public WindowsIdentity ImpersonationUser
               
    {
                    get
                   
    {
                       
    // Use the default Windows user.  Credentials will be
                       
    // provided by the NetworkCredentials property.
                       
    return null;
                   
    }
               
    }

               
    public ICredentials NetworkCredentials
               
    {
                    get
                   
    {
                       
    // Read the user information from the Web.config file. 
                       
    // By reading the information on demand instead of
                       
    // storing it, the credentials will not be stored in
                       
    // session, reducing the vulnerable surface area to the
                       
    // Web.config file, which can be secured with an ACL.

                       
    // User name
                       
    string userName = "xxx";

                       
    if (string.IsNullOrEmpty(userName))
                           
    throw new Exception(
                               
    "Missing user name from web.config file");

                       
    // Password
                       
    string password = "xxx";

                       
    if (string.IsNullOrEmpty(password))
                           
    throw new Exception(
                               
    "Missing password from web.config file");

                       
    // Domain
                       
    string domain = "xxx";

                       
    if (string.IsNullOrEmpty(domain))
                           
    throw new Exception(
                               
    "Missing domain from web.config file");

                       
    return new NetworkCredential(userName, password, domain);
                   
    }
               
    }

               
    public bool GetFormsCredentials(out Cookie authCookie,
                           
    out string userName, out string password,
                           
    out string authority)
               
    {
                    authCookie
    = null;
                    userName
    = null;
                    password
    = null;
                    authority
    = null;

                   
    // Not using form credentials
                   
    return false;
               
    }
           
    }


    Rick

    Tuesday, July 10, 2012 11:03 PM

Answers