views:

562

answers:

1

How do you pass in null parameters into a SQL 2008 Report? The code that interfaces with the ReportExecution & ReportService2005 web services always yields an error upon executing the ReportExecutionService.Render() method, after I set the parameters (not including the nullable one) via invoking the ReportExecutionService.SetExecutionParameters() method:

"...This report requires a default or user-defined value for the report parameter...to run or subscribe to this report, you must provide a parameter value."

even though that parameter is defined in the .rdl file as being nullable, and defaulting to null.

Must I change my code? Change parameter options in the .rdl file?

var rs = new ReportExecutionService();
rs.Url= "http://Z/ReportServer/ReportExecution2005.asmx";     
rs.Credentials = CredentialCache.DefaultCredentials;
rs.ExecutionHeaderValue = new ExecutionHeader();

var executionInfo = rs.LoadReport(ReportTarget, null);
var parameterList = new List<ParameterValue>();

foreach (ParameterValue parameter in Parameters)
{
  parameterList.Add(parameter);
}

foreach (var expectedParameter in executionInfo.Parameters)
{
  if 
  (  
      expectedParameter.Nullable && 
      !parameterList.Exists(delegate(ParameterValue pv) 
      { return pv.Name == expectedParameter.Name; })
  )
  {
     var parameter = new ParameterValue();
     parameter.Name = expectedParameter.Name;
     parameter.Value = null;

     parameterList.Add(parameter);
  }
}

rs.SetExecutionParameters(parameterList.ToArray(), "en-us");

Warning[] warnings = null;
string[] streamIDs = null;
string encoding = null;
string extension = null;
string mime = null;

var content = rs.Render("PDF", null, out extension, out mime, out encoding, out warnings, out streamIDs);
A: 

Does this answer from a slightly different question help? If not, perhaps more code would be helpful.

HTH

Mozy