i have a report that i have been sending a parameter to which worked just fine.
the report parameter was declared:
string[] pclist = new string(){ "A", "B", "C" };
ReportParameter pcode = new ReportParameter( "pcode", pclist, false );
which gives me a new report parameter that is initialized with a string array of 3 values. so far so good.
inside the report, the 'pcode' parameter is defined as a 'String', and is used like:
...
and PCode in ( #pcode )
...
recently, because the values for the parameter needed to change depending on who is logged in, we changed this such that the parameter gets it's string array from the return value of a method call. (the method gets the values from the database):
ReportParameter pcode = new ReportParameter( "pcode", FetchParams("X"), false );
FetchParams("X") performs a select on the database and returns a string[] of values. most of the time it works fine. however, sometimes the report does not run and only returns the error message:
The 'pcode' parameter is missing a value
what we determined is that sometimes there are dozens of values be returned by FetchParams("X"). when the number of values in the string[] gets too big, the report fails with that error message. apparently, there is some kind of upper limit to the number of values that can be used to instantiate a ReportParameter object.
initially we thought that the limitation might be in sql server itself as a limit to the number of values that can be handled by an in clause. however, the error message does not seem to support this conclusion.
edit: trial and error has shown for this particular case, 33 is the upper limit for the number of values in the string array.
does anyone have any experience with this problem?
is there an upper limit to the number of values in the array passed to the ReportParameter ctor?
is there a way to configure the upper limit to be a larger number?
any and all help will be appreciated.
thanks!
hokay, folks, here is the real answer to this bit of mystery.
the report has a parameter called 'pcode'.
the 'pcode' parameter has a data source that creates a list of drop down values.
now the code that runs the report is generating a list of values for the pcode parameter.
when the list of values is passed to the report, if there is a value that doesn't match the report's list generated from it's data source, you get the mind-numbing ssrs error message:
The 'pcode' parameter is missing a value
ug-ly. but that's m$ for ya.
for the record, there does not seem to be a limit to the number of values in the string array being passed to the ReportParameter ctor... that and the error message is coming from ssrs, not the code generating the ReportParameter object.
hope this might help someone else that has this problem.
Related
I am currently trying to work on fixing some cascading parameter issues I am having.
We recently put in a fix to a few SSRS reports that help with rerunning cascading parameters when the parent parameter is changed, if it helps, here is the instructions we followed to implement this: Cascading Parameters.
The main structure for most of our reports works like this:
#Hierarchy, select whether you want to filter by "Market" or "Region"
#HierarchySelection, select which markets or regions you want to filter by
#PropertyInternal, gets used to refresh #Property automatically each time #HierarchySelection is changed, this is populated by a SQL dataset
#Property, select which properties you want within those given markets or regions, the defaults are set up as Parameters.PropertyInternal.Value and get refreshed each time #HierarchySelection is changed
In order to get #Property to refresh properly, we have to feed #PropertyInterval with a NEWID() so it sees it as a new value each time it runs, so the value is CONCAT( Property, "|", NEWID() )...Property is always a 4 digit character
The issue I am having is that now is that subscriptions are failing because the Property parameter gets refreshed and unselects the values. Or if I have to feed it values, I can't exactly feed the NEWID() as I am unaware of what the value will be when the report is run.
My only thought is to try and remove the GUID from #PropertyInternal and feed that value to #Property instead, but either that is not possible or I just cannot figure out the syntax.
Any one have any better ideas for how I am handling this or if there is a way to remove the GUID?
I am essentially looking for something similar to this if possible, but getting the error below it.
=SPLIT(LEFT(JOIN(Parameters!PropertyInternal.Value,","), 4),",")
The report parameter 'Property' has expression-based ValidValues. The sizes of the value and the label (multi-value) arrays have to be identical. (rsInvalidValidValueList)
Public Function CommaSeparatedParam(ByVal strArray As Object()) As String
Dim returnStr As String = String.Empty
For Each str As String In strArray
returnStr = returnStr + Mid(str, 1, InStr(str, "|") - 1) + ","
Next
Return Left(returnStr, Len(returnStr) - 1)
End Function
I am building a report that I would like to accept two values from the user, feed those into a query, and find the data associated with those entries.
For example, if you had a list of employees, performance measures, and values associated with those; then the user would select an employee name / performance measure, and they would get the scoring information on that employee for that measure.
I have two parameters, each being populated from SQL queries getting a distinct list of employee names and measures, and a table below that just pulls up information based on ~ 'WHERE name = #Name AND measure = #Measure' but when I click 'Preview' to run the report locally I get the error: "one or more parameters required to run the report have not been specified"
I know the parameters are working properly because I can feed their values directly into a textbox and the values populate correctly. Also, if I change the query to just accept one parameter (i.e. WHERE measure = #Measure) the query works.
I'm confused as to why this error is occurring since I know my parameters are functioning and being populated properly.
I experienced this behavior in .NET 4.0 using Local Reports (in .rdlc files), when one of the parameter's values was containing an emtpy string. Although setting the parameter was correct:
report.SetParameters(
new List<ReportParameter> {
new ReportParameter("Title", Messages.Title),
new ReportParameter("SubTitle", Messages.Subtitle))
}
);
It worked only as long as both parameters actually contained some characters, otherwise the mentioned exception was thrown.
This error is caused when you either
A) the parameter is spelled wrong in the actual report. Meaning that the query is expecting #Name but the report is passing #Names (or some other spelling).
or
B) Is it possible you are attempting to run the report with a default value on the parameter of NULL for #Name but the stored procedure requires an actual value?
This might be happening if you are building the report in Visual Studio and gave the #Name parameter a default value of (null).
Try removing the default value or making sure you #Name parameter has an actual value, even if it's just ''.
I had similar issue. Issue happened when you use SharedDataSource with parameters that are to have null value. If you use same query in embeded data source, there is no problem.
Unlike embebed data source, you have to define if parameters used in query of shared data sources are allowed to have null value as highlighted in screenshot here. In my case, there are two parameters in query of shared data source, that can have null value.
So after setting them to allow null, problem fixed!
This caused me many hours of pain. Turns out that it's to do with using a shared dataset.
Embed the dataset within your report instead and it works fine.
For me, setting the value of the parameter makes problem. I don't know why, but the parameter value was not able to accept a string.Empty or null. So i just gave a " " as value solves the error.
Sample
ReportParameter[] parameters = new ReportParameter[4];
parameters[0] = new ReportParameter("Name", EName);
parameters[1] = new ReportParameter("ShiftName", CurrentShift);
parameters[2] = new ReportParameter("Date", LoginDate);
if(ValidateReportData())//some condition
{
parameters[3] = new ReportParameter("Date1", LoginDate);
}
else
{
//parameters[3] = new ReportParameter("Date1", string.Empty);//this makes exception while calling Render function.
parameters[3] = new ReportParameter("Date1", " ");//Solves the issue.
}
I was having the same problem, it is now sorted on sql server 2008 r2.
I know this is now an old question,
but just to help others:
It was very simple really, just making sure the spelling including the case is the same and the use of #.
I have a shared dataset called currentSpaceByDrive with the following code:
SELECT
[DRIVE]
,[Volume_Size_GB]
,[VolumeSpaceAvailable_GB]
,[VolumePercentAvailable]
FROM monitoring.dbo.currentSpaceByDrive(#ServerID)
I add the shared dataset currentSpaceByDrive to my report and I give it the same name.
when I right click on it, the one on my report, dataset properties, the parameter is #ServerID.
#ServerID value comes from another dataset, called the_servers (where the user selects a serverID)
I have a report parameter also called #ServerID that gets its value from the_servers and is used to feed the #ServerID parameter on currentSpaceByDrive.
Too many #ServerID, I understand, but if you do your own test based on this, you will get it done.
See the image attached.
hope this helps
marcelo
check DataSet In Report Server , I had Similar Problem , I was Editing Shared Dataset in Visual Studio , but it didn't work , after an hour of frustration I checked dataset in report server and I found out it Is not updating with changes I made in visual studio , I Delete it and Redeploy Dataset Again from visual studio . it works .
Actually I had to:
Delete the SubReport object from the report.
Drag new object from Toolbox
Setup the SubReport name and report
In Paramateres "Add", and choose each parameter, and related value.
Then is works for me.
I think I have same issue my Parameter Supervisor is blank when I choose "Select All" which causes the error "One or more parameters were not specified for the subreport", but if I select a few supervisor name then the sub-report appears. It is puzzling because the Manager parameter value shows all value when "Select All" is checked, but it is not working on my Supervisor parameter. Note that Supervisor parameter is dependent on manager parameter.
I'm using shared DataSets for several reports, and the root cause of this issue was not mapping the input parameters from the report itself to the parameters of the shared dataset.
To fix, I navigated to the "Report Data" panel, opened the dataset (which is really linking to a shared dataset), clicked the "Parameter" tab, and then mapped the report parameters to the parameters of the shared dataset.
I have to set the start_date of my report depending of a report parameter. The time stamps are calculated in a database query.
My expression looks like this:
=SWITCH (
Parameters!report_type.Value = 1,First(Fields!daily_start.Value, "Timestamps")
,Parameters!report_type.Value = 2,First(Fields!weekly_start.Value, "Timestamps")
,Parameters!report_type.Value = 3,First(Fields!monthly_start.Value, "Timestamps")
)
Unfortunately I get the error message:
A value expression used for the report parameter 'time_from' refers to a field. Fields cannot be used in report parameter expression
I know, that this is not allowed because SSRS cannot be sure in which order datasets are called. But I think this is not dangerous.
All time stamps are received by query without parameter. The parameter report_type is selected by a user before the report will be generated.
Can someone give me a hint for a workaround?
Here's the workaround - get the value using SQL.
Create a new Dataset called StartDates:
SELECT CASE
WHEN #report_type = 1 THEN daily_start
WHEN #report_type = 2 THEN weekly_start
WHEN #report_type = 3 THEN monthly_start
END AS StartDate
FROM MyTable
You already have the #report_type and #time_from parameters. With the #time_from parameter, set its Default Values to Get values from a query using the StartDates dataset and the Value field StartDate.
Now, you'd think this might be enough to make it work - you're referencing this query as the default value and as you change the #report_type parameter the other parameters refresh, but the first date in the #time_from parameter never changes. That's because the refresh happens on the Available Values query, not on the Default Values query.
So you also need to wire up the Available Values query to the StartDates query. Now your query will fire on the change of #report_type and the default value will be set to the appropriate date for your selection.
I switched from a query to Stored Procedure and was getting this error. Things I tried:
Ensured I had sufficient permission on the database (you need EXEC rights or DBO to run teh sproc)
Delete the existing parameters (and then use refresh fields to refresh/get the correctly named ones back)
Remove the square brackets around the stored procedure if you've specified that
Sometimes, Expressions can get a bit verbose. I have created a Report Code Function and then used that as the Parameter Value.
For example, I created a Code function called "CalculateDateSet" and then set the Report Parameter to this expression:
"=Code.CalculateDateSet(Parameters!Month.Value, Parameters!Year.Value"
How can I loop through the rows of a dataset in the custom code?
I have a report containing a dataset. I pass the dataset as a parameter to the custom code function. But what then? Where is a reference about the available members etc.?
Here is my dummy sample code so far:
Public Function ShowParameterValues(ByVal ds as DataSet) as object()
Dim codes() As Object
Array.Resize(codes,dc.???.Count)
codes(0)=ds??(field???)(row??)
return codes
End Function
Please note: this will be a very simple script (if it'll work), so I don't want to go into custom assemblies etc.
I think you got your answer at:
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/a7d59224-0ee5-491e-883b-2e5fcb3edeab/iterate-through-rows-of-dataset-in-reports-custom-code?forum=sqlreportingservices
There were two important pieces of information I was able to grasp from the above link:
First, A dataset in Reporting Services is not the same type of object as an ADO.Net dataset. A report dataset is an internal object managed by the SSRS runtime (it's actually derived from a DataReader object) and not an XML structure containing datatables, etc. and cannot be passed into the report's custom code.
Second, There was a solution posted as to how one can Iterate through rows of dataset in report's custom code by "transforming" the data set into a multivalued parameter (or if several fields are needed, transforming it in multiple multivalued parameters):
The multivalued Report Parameter must have the following characteristics:
Hidden = True, Allow Multiple Values = True
Available Values tab: Choose the desired dataset. Select the searchable id as Value id, and the field you want to expose as Label Field.
Default Values Tab: Get Values from a Query.
Choose the same Dataset as choosen in the available Values Tab.
Value Field the same you choose for value id.
Set the parameter to never refresh (or it will be loading the data from each iteraction of another parameter).
Now, the idea is make this Parameter "searchable". From this point you exposed the Dataset as an array in the Multi valued Parameter.
Now in a custom code insert the following code:
function GetDataSetLabelFromValue( id as integer) as String
dim i as integer
i = 0
for i = 1 to Report.Parameters!YourParameter.Count()
if Report.Parameters!YourParameter.Value(i) = id then
GetDataSetLabelFromValue = Report.YourParameter!ReportParameter1.Label(i)
Exit For
End if
next i
End Function
Were you able to do what you wanted?
I have a textbox in my SSRS 2005 report. The expresssion for this textbox is:
=IIF(IsDBNull(Fields!fOrgID), Code.SetMyVar("null"), Code.SetMyVar(Fields!fOrgID.Value))
I have also tried IsNothing(Fields!fOrgID) and a few other variations of checking for nulls.
I have modified the SetMyVar function for testing and it now looks like this:
Public Function SetMyVar (var as String)
MsgBox(var, VbOKCancel, "Test1")
If var Is Nothing Then
Return "NOTHING"
Else
MyVar = var
Return var
End If
End Function
I also have the public variable MyVar:
Public Shared Dim MyVar as String
When my database query returns data, this correctly evaluates, a messagebox is displayed with the value, the textbox gets set with the value, and the world is generally a happier place.
When my database query does not return a value though, I get the error:
The query returned no rows for the data set. The expression therefore
evaluates to null.
and the SetMyVar function never appears to be ran (you never get the messagebox popup). As expected, my emotions range from anger, sadness, and bitter hatred of SSRS.
I read something about SSRS evaluating both sides of an IF statement, so perhaps that is why I get the error (likely then on Code.SetMyVar(Fields!fOrgID.Value))... not sure how I get around that though.
Thoughts? Suggestions? Words of comfort?
From the sound of things, it seems likely that the issue is that SSRS is having a problem displaying zero records. I'd recommend one of the following:
1) Use a control that handles zero records appropriately (Tables do. I think Lists do as well).
2) Modify your query to return a single record with blank values if it would otherwise return zero records.
An answer to the original question:
=IIF(IsNothing(Fields!fOrgID),
Code.SetMyVar("null"),
Code.SetMyVar(IIF(IsNothing(Fields!fOrgID),"Foo",Fields!fOrgID.Value)))
The error was from both sides of IIF being evaluated. The extra IIF in the statement above will avoid Code.SetMyVar from ever being called with a null value.
I believe you're right about about Iif always evaluating both of its value arguments (at least, it does in Visual Basic). I'm not sure why you're getting this precise error (unless strings can't be assigned a value of DBNull?), but you almost certainly want to attack this problem with a different method.
The reason for this is that your current code will likely always call both set methods regardless of the conditional value.
Formula that worked for my SSRS 2008 reports.
=IIf(String.IsNullOrEmpty(Fields!NullableFieldwithPossibleBlankStrings.Value),"Yes","No")
I tried this too (also tried a version with IsNothing)...
=Code.SetField(IsDBNull(Fields!fOrgID))
And changed the function to be one that accepts a boolean. I figure this above function would always return a true or false, but in the event of a NULL, I again get "The query returned no rows for the data set. The expression therefore evaluates to null.".
I need to pass back to my code if the field is null or not (as this will let me know if the datasource is null or not).
Let me know if you can think of a better way because I cannot.