SSRS passing hidden parameter from web.config - c#

I have a report that deals with presenting a table with data, I use the MvcReportViewerFluent to view the report on the page.
#(Html.MvcReportViewerFluent(Model.ReportPath)
.ReportParameters(Model.ReportParameter)
.Attributes(new { Height = 900, Width = "100%", style = "border: none" })
.ControlSettings(new ControlSettings() {ShowExportControls=true, AsyncRendering=true, ShowReportBody=true })
)
In the report there is a link that is built with the concatenation of various parameters including the baseUrl parameter of the hidden type, for a couple of days this parameter seems as if it were not populated but took its default value.
To populate this parameter I use the ReportParameters property to which I pass a dictionary with the parameter.
model.ReportParameter = new Dictionary<string, object>();
model.ReportParameter.Add("BaseUrl", ConfigurationManager.AppSettings["UrlBase"].ToString());
Note that in addition to this parameter, other parameters that work perfectly are presented on the screen.
I also tried to make this parameter visible and I saw that it is not even populated, the strange fact is that in the test environment it gave the same problem which then solved itself without making any changes.

Not sure exactly what you meant by "the baseUrl parameter of the hidden type". In order to pass hidden parameters to ssrs you just append it to a query string like so:
[BaseurlofSSRS]?[myhiddenparamname]=[value]
This should work.

This was due to a cache problem that remained hanging on the server after some changes were made to the report itself, for some reason the parameters were not updated, the solution was to delete the report and reload it on the server.

Related

Parameters not being passed correctly through code

My report gets data from a stored procedure. Two of the six parameters are dates (toDate and fromDate.) I integrate the report with C# Winforms and I pass the parameters through code the code with:
reportDocument.setParamterValue(0,paramValue);
The report works fine but does not render data despite showing the column header properly. When I refresh the report, it pops up the parameter window again. When I enter the parameters through that window the data shows, including column headers. But it doesn't work when I pass parameters through code.
How can I resolve this?
It looks like this:
CRPT.SetParameterValue("smonth", Servercls.month);
See this link for more info.
I suggest first of all call procedure in c# environment and save result in datatable and then send datatable to crystal report.
I found the error.
First it was not working with setting parameters through indexing. so i set the parameters through name as reds suggested.
second i was missing the parameters binding with report viewer object.
so i added the following line and it worked
crystalReportViewer.ParameterField.addRange(reportDocument.ParameterFields);
Thanks for the answers guys.

SSRS report parameter

I have a problem with rendering report with correct parameter.
We have RDL report that has date parameter with default value which is an expression "=today()".
In project i have the following code in c#
for(int i = 0; i < 15; i++)
{
serverReport.SetParameters(new ReportParameter("dt1",date.ToString()));
File.WriteAllBytes(path, serverReport.Render("PDF"));
}
For first iteration sql stored procedure is called with the default parameter and following iterations are called with passed date(i checked it with sql profiler).
I want to mension that in loop i have many other reports with exact same default date parameter but the problem is with this one. I have compared all parameter properties in 2 repors(one that works and the other that is not working properly), but they are identical. I cant find any difference.
If i delete default value "=today()" then report is working fine.
Maybe sameone had similar problem and recommend me something about this. Thanks in advance.
A few things to check:
SetParameters takes IEnumerable<ReportParameter> not a single ReportParameter object. Call it like this instead:
serverReport.SetParameters(new ReportParameter[] { ReportParameter("dt1", date.ToString()) } );
Make sure that the parameter does not have the available values filled in as well as the default value. If the date passed is not one of the valid values (if applied) it won't work. For example, if the available values are set to =Today then the only report that will run properly is the first one that coincidentally uses that value.
Are you sure that date.ToString() is passing an appropriate and valid date?
Does the server's report parameter match the development environment? Parameter settings aren't automatically updated so that any modifications made on the server aren't overwritten by deploying the report again. Check the server's report parameters and update if necessary, or simply delete and redeploy the report.
Try to completely remove the not working report within the server (and to test,also one of the working) and re-deploy both to the server. you could also check in reporting manager for the parameter settings, because there the difference might be visible.
I had that kind of issues before with report parameters and know that the parameter settings are not overwritten correctly all the time you deploy the report.

SSRS with 'Available Values By Query' does not return ValidValues property

I have a web application using a SSRS 2010 service, and I'm having an issue getting back the valid values for a parameter. The parameter allows multiple values and is of type Text. In the report I create, I am getting available values by query, as opposed to 'specify values'. When I call GetItemParameters the ValidValues property is empty.
If my Report specifies values instead of getting values from query, then the ValidValues property is filled in completely.
I'm hoping someone knows a way to get that property filled out when getting from query, because I'd hate to have my report writers specifying hundreds of (often changing) values individually.
Thanks!
Your link ReportingService2010.GetItemParameters gives following information
If any parameters values are based on a query and you are interested
in returning the query-based parameters' valid values list, set
ForRendering to true. In addition, for query-based parameters, you
must pass in all of the credential information required to return the
query parameters.
Did you set ForRendering to true value as it is said in this link?

Deploying report that's populating DataSet based on a parameter passed into the ReportViewer

I am new to reporting services and to using the report viewer control in an aspx (C#). I am currently working on a project where I need to populate a report based on region. I am using SQL Express 2008 R2.
I have created a region parameter in the report, which is populated with a dataset using the following query:
SELECT RegionGUID, RegionDescription
FROM utRegion
This then creates a DropDownList with the available values, which I then use in my main report dataset to obtain my results based on the region selected.
The issue I have, is users in my application are assigned to regions and depending on who's logged into my application should restrict what regions are available via reporting services. I am able to pass parameters from my application via the report viewer to my report in reporting services, but when I try adding a parameter to my dataset that is used to populate the region DropDownList I get the following error when deploying:
The definition of the report '/Report name' is invalid
and the following error when previewing:
The report parameter 'RegionGUID' has a DefaultValue' or a ValidValue that depends on the report parameter "RegionGUID". Forward dependencies are not valid.
My query with the region parameter:
SELECT RegionGUID, RegionDescription
FROM utRegion
WHERE (RegionGUID = #RegionGUID)
I found the solution to my issue on the following site:
http://www.sqlservercentral.com/Forums/Topic306513-150-1.aspx
As stated by Jason Selburg in the above link, It seems that the order of the parameter list is important.
To make my application work I done the following:
Deleted my existing RegionGUID Parameter
Added a New Parameter called UserAssignedRegion with the Available Values of not specified and the visibility of hidden
Re-added my RegionGUID Parameter (visibility: visible) and set it to use the following query:
Query:
SELECT RegionGUID, RegionDescription
FROM utRegions
WHERE RegionGUID = #UserAssignedRegion
You should inspect the properties of the #RegionGUID parameter, specifically the DefaultValue or ValidValue tab. Either or both may depend on a dataset that uses the parameter itself in its query. You can't query a default or valid value for a parameter while using that parameter itself.
A typical query for available values would be:
SELECT DISTINCT RegionGUID -- For value
,RegionDescription -- For label
FROM utRegion
-- No where clause, you can't or need to use the parameter itself
The query for the default value may be the same (perhaps only use the First(...) value), NULL, or based on a different dataset (that also does not use the parameter itself)

Microsoft Reporting: Setting subreport parameters in code

How can I set a parameter of a sub-report? I have successfully hooked myself up to the SubreportProcessing event, I can find the correct sub-report through e.ReportPath, and I can add datasources through e.DataSources.Add. But I find no way of adding report parameters??
I have found people suggesting to add them to the master report, but I don't really want to do that, since the master report shouldn't have to be connected to the sub-report at all, other than that it is wrapping the sub-report.
I am using one report as a master template, printing name of the report, page numbers etc. And the subreport is going to be the report itself. And if I could only find a way to set those report parameters of the sub-report I would be good to go...
Clarification: Creating/Defining the parameters is not the problem. The problem is to set their values. I thought the natural thing to do was to do it in the SubreportProcessing event. And the SubreportProcessingEventArgs do in fact have a Parameters property. But it is read only! So how do you use that? How can I set their value?
It does work but it sure is persnickety.
First thing I recommend is to develop your reports as .rdl. Much easier to test the reports this way. You can also get the subreport parameters set up and tested as rdl, making sure each parameter of the subreport is also defined as a parameter of the parent report. Once you get the reports - including the subreports - working that way you can rename the .rdl to rdlc and add the rdlc files to your ReportViewer Project. No further changes required. Use the names of the rdl datasources as the data source names in your code to provide data to the report in the SubreportProcessing event handler.
You don't assign values to the passed parameter. The subreport will use them as is. (Sounds like the step you are missing is adding the parameters to the parent report as well as the the subreport as mentioned above.) You can evaluate the parameters and use them as query parameters to get the datasource you will add.
You have to think about the datasource like its on an undiscovered dimension for a subreport. You will have to poke around while debugging in the event handler to see what I mean. Some of the values in your application will be readily available, others that you use easily elsewhere will throw object not found exceptions. For example I create a dataset in a instance of a class created on my applications main form. I use the data set throughout my application. In the SubreportProcessing event handler I cannot use the common dataset, so I must create a new instance of the table I need for the report and populate it. In the main report I would be able to access the common dataset. There are other limitations like this. Just have to wade your way through.
Here is the SubreportProcessing event handler from a working VB.NET ReportViewer application. Shows a few different ways to get the datasource for a subreport. subreport1 builds a one row datatable from application business objects, subreport2 provides data the report requires without a parameter, subreport3 is lie subreport2 but evaluates one of the parameters passed to the subreport for use in date value required by the query that creates the ReportDataSource.
Public Sub SubreportProcessingEventHandler(ByVal sender As Object, _
ByVal e As SubreportProcessingEventArgs)
Select Case e.ReportPath
Case "subreport1"
Dim tbl As DataTable = New DataTable("TableName")
Dim Status As DataColumn = New DataColumn
Status.DataType = System.Type.GetType("System.String")
Status.ColumnName = "Status"
tbl.Columns.Add(Status)
Dim Account As DataColumn = New DataColumn
Account.DataType = System.Type.GetType("System.String")
Account.ColumnName = "Account"
tbl.Columns.Add(Account)
Dim rw As DataRow = tbl.NewRow()
rw("Status") = core.GetStatus
rw("Account") = core.Account
tbl.Rows.Add(rw)
e.DataSources.Add(New ReportDataSource("ReportDatasourceName", tbl))
Case "subreport2"
core.DAL.cnStr = My.Settings.cnStr
core.DAL.LoadSchedule()
e.DataSources.Add(New ReportDataSource("ScheduledTasks", _
My.Forms.Mother.DAL.dsSQLCfg.tSchedule))
Case "subreport3"
core.DAL.cnStr = My.Settings.cnStr
Dim dt As DataTable = core.DAL.GetNodesForDateRange(DateAdd("d", _
-1 * CInt(e.Parameters("NumberOfDays").Values(0)), _
Today), _
Now)
e.DataSources.Add(New ReportDataSource("Summary", dt))
End Select
End Sub
Recently I had the same problem and with all the search I didn't find anything helpful but finally I came to a solution for this.
I created a class having all the parameteres in the subreport as it's properties(we can call it a DTO)
public class MyDto
{
public string EmployeeFirstName{get; set;}
public string EmployeeLastName{get; set;}
// and so on
}
Then used a list of this type as another datasource in the main report and then in 'Subreport properties' added a parameter for each parameter in the actual subreport and chose the corresponding fields from the datasource as their values.
then when loading the report convert the input(list of Employees) to a list of MyDto and set it as the reports's datasource :
private void LoadReport(List<Employee> employees)
{
reportviewerMain.ProcessingMode = ProcessingMode.Local;
reportviewerMain.LocalReport.ReportPath = Application.StartupPath + "\\Reports\\PayChecksReport.rdlc";
List<MyDto> employeesDataSource = employees.ConvertAll<MyDto>(emp => new MyDto { EmployeeFirstName = emp.FirstName, EmployeeLastName = emp.LastName}).ToList();
reportviewerMain.LocalReport.DataSources.Add(new ReportDataSource("EmployeesDataSet", employeesDataSource));
Organization myOrganization = new OranizationFacade().GetOrganizationInfo();
reportviewerMain.LocalReport.SetParameters(new ReportParameter("OrganizationName", myOrganization.Name));
this.reportviewerMain.RefreshReport();
}
And...
It did the trick for me :) I hope it helps somebody.
I know this is an old question which has been marked as answered, but since I was just searching for this today and I saw that it had been commented on within the last few months I thought I'd throw a follow up answer in.
In order to render the subreport in the context of each record on the main report, you need to declare a SubreportProcessingEventHandler and then inside that handler load the DataSet for each instance of the subreport as it occurs. SubreportProcessingEventArgs has a parameters collection which is passed from the parent report when the event fires.
So if you have configured the subreport parameters on the main report with like named parameters bound to fields on the main report, the values are accessible as the subreport is rendered.
Here is a very good write up that explains far more clearly.
I had a similar problem in that I needed to pass a Properties.Settings.... value to prepend to the path in the database. To do this I had to set a property in the main report and use that property to set the second property in the subreport. Setting the main property then in turn sets the subreport property. YOU CAN set the main property in code as follows:
Suppose you have a ReportViewer name rv, then we would code:
var rp = new ReportParameter("MainReportParamName", Properties.Settings....);
rv.LocalReport.SetParameters(new ReportParameters[] { rp });
You could add them via the xml definition. I use xml to create an entire report based on selected sub-reports and other options. I can paste some code in here come Monday if you would like to look at this as a possible solution.
Edit: You can set values on the sub-report in the XML before you deploy the report. This is not very flexible and I am making the assumption that if you want to prompt for these values, you will most likely need them on the parent report.
If you want to see what the XML looks like, add a sub-report, enter values for it in the sub-report properties > parameters, then do a view code.
<Subreport Name="subreport1">
<Parameters>
<Parameter Name="StartDate">
<Value>=Parameters!StartDate.Value</Value>
</Parameter>
<Parameter Name="EndDate">
<Value>1/1/2009</Value>
</Parameter>
Instead of using the =Parameters!StartDate.Value I'm guessing you would want to put an actual value like on the EndDate.
After looking and looking, I have come to the conclusion that setting the parameters of a sub-report, in code, is not possible. Unless you do something fancy like start editing the xml of the report definition before you load it or something like that.
(But if someone else should know that I am wrong, please do answer, cause I am still very curious to know!)
Svish - I'm not sure which side of the plumbing you're having trouble with.
To add parameters to the parent report open it then right click on the subreport and select Properties > Parameters.
You can then define parameter names and assign them a value, e.g.
Parameter Name | Parameter Value
---------------+---------------------
MyParameter | =Fields!Params.Value
So on this side of the plumbing the parameters get their value from the parent report data source.
To add parameters to a subreport open the subreport and from the toolbar select Report > Report Parameters
Here you define a parameter to receive the parameter from the parent report, e.g.
Name | myParameter
----------+---------------------
Data Type | String
For what it sounds like you want to do can't you do away with a subreport and just have the one report anyway? The information you're trying to wrap around the report sounds ideal for just including in the headers and footers of the report.

Categories

Resources