SQL report with subreport not showing on page - c#

I have created a SQL report using Visual Studio (also works when using Report Builder). The report consists of the main report with sub reports in it. When running the report via Visual Studio or Report Builder or publishing to the Report Server, it works fine and the main report and sub reports show correctly.
I have an ASP.Net MVC application which displays the report but it also allows the user to specify a where clause before running it. When the report is run via the MVC application, it shows only the main report and then says:
The subreport 'sub' could not be found at the specified location
[MVC application direcotry] Please verify that the subreport has been
published and that the name is correct.
even though the report is there.
The following is a snippet of the code which loads and displays the report:
if (ReportFileName != null && ReportFileName != "")
{
ViewBag.Title = "Reporting";
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.SizeToReportContent = true;
reportViewer.Width = Unit.Percentage(100);
reportViewer.BackColor = System.Drawing.Color.White;
reportViewer.Height = Unit.Percentage(100);
SqlConnection conx = new SqlConnection(ConfigurationManager.ConnectionStrings[""].ConnectionString);
SqlDataAdapter adp = new SqlDataAdapter(Basequery, conx);
DataTable dt = new DataTable();
adp.Fill(dt);
adp.Fill(ds.Tables[0]);
reportViewer.LocalReport.ReportPath = ReportFileName;
}
reportViewer.LocalReport.DataSources.Clear();
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("ReportDataSet", ds.Tables[0]));
reportViewer.LocalReport.Refresh();
ViewBag.ReportViewer = reportViewer;
return PartialView("ReportView");
is there something that im missing?

Related

How can I redirect to Report Viewer?

I am facing a problem while working with Reports in WPF... I have created an event
private void Window_Loaded(object sender, RoutedEventArgs e) {
try {
admissionReportViewer.Owner = Window.GetWindow(this);
if (_admissionNumber != 0) {
rd.Load(#"C:\\Users\Sohaib Khalid\source\repos\SMS Degree College\Reports\AdmissionForm - Copy.rpt");
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["Other"].ConnectionString;
conn.Open();
SqlDataAdapter sda = new SqlDataAdapter("SearchStudentInfoAllById", conn);
sda.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;
sda.SelectCommand.Parameters.AddWithValue("#AdmissionNumber", _admissionNumber);
sda.SelectCommand.Parameters.AddWithValue("#Active", _active);
DataSet ds = new DataSet();
sda.Fill(ds, "StudentTable");
rd.SetDataSource(ds);
admissionReportViewer.ViewerCore.ReportSource = rd;
}
}
catch(Exception err) {
this.ShowMessageAsync("No data", err.ToString());
Debug.WriteLine(err.ToString());
}
after this report also load but it again, ask for parameters:
and also credentials of server login
Can Anybody tell me why it is again asking for parameters?
Thanks
I never used ReportViewer in WPF app, but used it a couple of time on ASP.NET
If WPF works in the same way, you're code is wrong:
The report is using the data source you set up for design it and not the one you're passing to it
You're storing the parameter value in the data adapter (query) and not in the report parameters
This is why your report ask for both.
I'll share a bit of code for ASP, try to check if it can be the same for WPF or if you have to change it:
// Local mode says to use the datasource we are giving to the report
// instead of the one we used to design it
reportViewer.ProcessingMode = ProcessingMode.Local;
// Set the path of the report file
LocalReport localReport = reportViewer.LocalReport;
localReport.ReportPath = "PATH_OF_YOUR_REPORT";
// Extract data from the DB (remember to insert the parameters in the query)
var dataset = GetDataSet();
// Assign the dataset to the report source (we need a ReportDataSource)
var source = new ReportDataSource();
source.Name = "SOURCE_NAME_USED_IN_THE_REPORT";
source.Value = dataset.Tables["YOUR_TABLE"];
// Add the source to the report
localReport.DataSources.Add(source);
// Create your report parameter (ex: fromDate)
var paramFromDate = new ReportParameter();
paramDataDa.Name = "fromDate";
paramDataDa.Values.Add(paramFromDate.ToShortDateString());
// Set the report parameters for the report
localReport.SetParameters(new ReportParameter[] { fromDate });
I hope this can help you but remember, it is for ASP and not for WPF.
So try to adapt it to WPF and see if they work in the same way

Error while getting multiple Datasets in RDLC report

I have a RDLC report with two datasets and it gives 'The definition of the report C:\Employee.rdlc' is invalid error whenever it runs. The report works fine if i only use one dataset.
Here is the setup:
For the report, i have added one datasource (i.e. Dataset) (name: 'dtsrcEmployee'' and used 'TableAdapter' to add two existing stored procedures from the existing database. In the report, i have added this dataset as DataSource. Also in report, i have added two dataset (name: dtGetEmployeeSummary, dtGetEmployeeStats) which points to two datatable from the datasource.
From the code side, i am passing dataset which has two datatable(datatable names matches with each dataset name in the Report) (i.e dtGetEmployeeSummary, dtGetEmployeeStats). Also i am using 'First' tag in report fields as mentioned here
ReportViewer reportViewer = new ReportViewer();
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.SizeToReportContent = true;
reportViewer.Width = Unit.Percentage(100);
reportViewer.Height = Unit.Percentage(100);
reportViewer.ShowZoomControl = false;
reportViewer.ShowRefreshButton = false;
reportViewer.ShowBackButton = false;
reportViewer.ShowFindControls = false;
reportViewer.LocalReport.ReportPath = reportPath;
foreach (DataTable reportTable in reportDataSet.Tables)
{
reportViewer.LocalReport.DataSources.Add(new ReportDataSource(reportTable.TableName, reportTable));
}
var resportParameterLists = new List<ReportParameter>();
foreach (var keyValuePair in parameters)
{
resportParameterLists.Add(new ReportParameter(keyValuePair.Key, keyValuePair.Value));
}
reportViewer.LocalReport.SetParameters(resportParameterLists);
reportViewer.LocalReport.Refresh();
return reportViewer;
Any idea why i am getting error while using second dataset but not while using only one?
Thanks
Update: I ended up deleting the report and created new one with two
datasets and Yes it worked this time. Not sure what was wrong with old
report.

Why getting this error :Specified cast is not valid

I am using this code to open crystal report in VS2010 ,axCRViewer1 is crystal report viewer control name , but getting error at this line
axCRViewer1.ReportSource = rptDoc;
How do I fix it ?
private void ViewR_Load(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
DataSetPatient ds = new DataSetPatient(); // .xsd file name
DataTable dt1 = new DataTable();
DataTable dt = DBHandling.GetPatient();//getting data using GetPatient()
// Just set the name of data table
dt.TableName = "Crystal Report P";
ds.Tables[0].Merge(dt);
// Your .rpt file path will be below
rptDoc.Load("C:\\Users\\Monika\\Documents\\Visual Studio 2010\\Projects\\SonoRepo\\SonoRepo\\Reports\\CrystalReportP.rpt");
//set dataset to the report viewer.
rptDoc.SetDataSource(ds);
axCRViewer1.ReportSource = rptDoc;//getting error at this line
// code to get data from the DB
}
Getpatient() Code
public static DataTable GetPatient()
{
DataTable patientTable = new DataTable();
using (OleDbConnection con = new OleDbConnection(#"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=sonorepo.mdb"))
{
using (OleDbDataAdapter da = new OleDbDataAdapter(#"SELECT PatientID,PFirstName FROM Patient_Registration", con))
da.Fill(patientTable);
}
return patientTable;
}
This message is coming from the data. Check if the structure of DataTable dt is the same as the structure of the first table in DataSetPatient.
You can also try to replace the code for DataSetPatient.
DataSetPatient ds = new DataSetPatient(); // .xsd file name
....
ds.Tables[0].Merge(dt);
with
DataSet ds = new Dataset()
ds.Tables.Add
Here is what worked for me:
If you are installing on a 64-bit machine, make sure the application properties under the Build tab have "Any CPU" as the platform target, and unselect the check box for "Prefer 32-bit" if you have the option. Crystal is very touchy about 32/64 bit assemblies, and makes some pretty counterintuitive assumptions which are very difficult to troubleshoot.

Unable to bind datasource to reportViewer

I have a C# application that uses a reportViewer. I want to add 3 reports in a single reportViewer. Here is the code for a single report:
ReportDataSource rds = new ReportDataSource();
this.reportViewer1.LocalReport.DataSources.Clear();
if (comboBoxReports.SelectedIndex == 0)
{
reportViewer1.Reset();
reportViewer1.LocalReport.ReportPath = "D:\\AMOS\\WindowsFormsApplication1\\WindowsFormsApplication1\\Report2.rdlc";
rds.Name = "First_Year_IT_AttendanceBindingSource";
rds.Value = this.First_Year_IT_AttendanceBindingSource;
reportViewer1.LocalReport.DataSources.Add(rds);
this.reportViewer1.RefreshReport();
}
However when I run my application, I get the following error
A data source instance has not been supplied for the data source 'DataSet1'
What can be the possible mistake?
Open rdlc file as text
Replace DataSet1 with First_Year_IT_AttendanceBindingSource
Check that the columns (fields) in rdlc is 'equal' to columns in your data source

Report viewer can't access reports in other database server

I have a web application in asp.net 3.5 published in apps server.I have few SSRS reports deployed in a database server which needed to be accessed from the web app.Both the server are in same network.I am using a report viewer control to show the reports and i am passing the report path dynamically.I am also sending the login credentials from code behind.
The problem is that the report is identified correctly and the proper report parameter are also shown.But when i click the view report button no data appears.I have Sql server 2008 r2 and report viewer version 9.0
Please help me with this. here is a code snippet...
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ReportViewer1.ShowCredentialPrompts = false;
IReportServerCredentials irsc =
new CustomReportCredentials("user", "pass", "domain");
ReportViewer1.ServerReport.ReportServerCredentials = irsc;
ReportViewer1.ServerReport.ReportServerUrl =
new Uri("http://72.0.170.205:80/ReportServer");
ReportViewer1.ShowParameterPrompts = true;
ReportViewer1.ShowPrintButton = true;
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ReportViewer1.ServerReport.Refresh();
ReportViewer1.ServerReport.ReportPath = Request.QueryString["val"];
}
}
Did you check that the reports run ok with the same credentials on http://72.0.170.205:80/Reports ?
Don't know if this can be of any help but here are the differences I see in my implementation :
I don't call ReportViewer1.ServerReport.Refresh();
I call this.RegisterRequiresViewStateEncryption(); ( Had to disable it sometimes )
my reportDisplay application is not the root app. Because of conflicts, back in SSRS2005 I had to use a different name for its session cookie in the web.config. Kept it since then
<sessionState cookieless="UseCookies" cookieName="ASP.NET_SessionId.myCustomName"/>
Protected Sub Load_Report()
Dim Connection As New SqlConnection(Connection_String) 'Server Connection String
Dim Data_Table As New DataTable("DataTable1") *'Create New Data Table in DataSet having same columns as are there in your Datatable*
Dim Query As String
Query = "SELECT Caption,Mobile,Age,City FROM Bond.Book"
Dim Command As New SqlCommand(Query, Connection)
Dim Table_Adapter As New SqlDataAdapter(Command)
Table_Adapter.Fill(Data_Table)
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = Server.MapPath("Book.rdlc")
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Book_DataSet", Data_Table))
ReportViewer1.LocalReport.Refresh()
End Sub
This worked for me. I am able to load report viewer on server and view server data

Categories