0

I was tasked with making a Webpage (aspx), which automaticly reads rdlcs, and generates a webpage, with the parameters at the top as webelements and the report as the main part of the page.

So far, I have tried reading the file as an XML-Doc, and just parsing the info out of there. But this may be done simpler. (I have no expirience with reports or rdl(c) files).

I have seen that there is a DataSets/DataSet/Query/CommandText-Tag, which can hold an SQL-Statement. Now this let's my boss and myself assume, that it is possible to make it already deliver this info by itself, which me coding this. On the other hand, I see nowhere any example for that.

My current code looks like this:

private string rdlcFilepath = "some/path/to/file.rdlc";
protected void Page_Load(object sender, EventArgs e) {
    string sql = GetSqlStatementFromRdlcFile(rdlcFilepath);
    DataTable dtTest = DatabseFacade.Execute_SQL(sql);

    MainReportViewer.LocalReport.ReportPath = Server.MapPath(rdlcFilepath);
    MainReportViewer.ProcessingMode = ProcessingMode.Local;
    MainReportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dtTest));
    MainReportViewer.LocalReport.Refresh();
}

So, I have 2 theories:

  1. The CommandText-Tag tag is a ment for a "report server" and should be used only in ProcessingMode.Remote, and is not relevant when in Local mode.
  2. I'm approaching this whole thing wrong.

If 2 is true, then probably the problem is manually adding the dtTest, and it should have some other instruction to make the report-element "pull" the data by itself.

My questions:

  • Is one of my assumptions correct, or what is going on?
  • Any other hints/links that may help?

I may note, that every tutorial/example I saw on the internet, that used ProcessingMode.Local, used an "external" datatable, and the LocalReport.DataSources.Add way.

Just for clearification, our (my boss' and my) ideal solution, would be some "magic" command, that makes the ReportViewer, use the information in the rdlc file, to connect to the database, and display the result. After all it contains all of the info, from connection-string to SQL-statement.

Ramzi Khahil
  • 4,932
  • 4
  • 35
  • 69
  • Were you able to figure it out? I am too trying to pull SQL data directly from ReportViewer. – Mark Mar 08 '23 at 11:13
  • @Mark I don't really remember, and I don't work at that company anymore. So I can say out of memory: yes and no. I remember it somehow working, and then me still replacing strings in the XML, because we needed the report to be displayed in different languages. What I can tell you, is that I spent a lot of time with the docs, and in the end I could make all sorts of things work. So best thing you can do is: spend a few days with the docs and experiment. Try to understand things, without thinking "how does this help me, with the task at hand?". Good luck. – Ramzi Khahil Mar 10 '23 at 14:47

1 Answers1

0

Please note that the rdl file is the Native SSRS report version, which is faster and easier to develop. The type of Project needed here is "Reporting Services Project", while the rdlc is the client side of the rdl file which is usually developed in normal visual studio web or desktop project, which is of course used as local report and usually takes more time to develop and you have to provide all DataSources, DataSets and Parametrs if there is any. In my opinion, there is much simpler solution to your problem. You can actually setup remote or local SSRS reporting services server and this will enable you to work on the reports(rdl files) natively, which is basically cleaner and faster. In terms of performance too, I think that native mode scales out and outperform the local or client report option (.rdlc). Using this approach, you don't have to add DataSources or Datasets or Parametrs as all of this you will configure natively and use the configuration manager to configure Shared DataSources and Datasets. You will only have to authinticate the use in your page and provide the URI of your SSRS server, User name, password and report path. To know more about configuring SSRS Server use this link please: SQL Server Reporting Service Configuration Manager

there are also a lot of links online. You can authinticate the user like the below code sample shows:

                // Set the processing mode for the ReportViewer to Remote  
                ReportViewer1.ProcessingMode = ProcessingMode.Remote;
                ServerReport serverReport = ReportViewer1.ServerReport;
                ReportViewer1.ServerReport.ReportServerCredentials = new CustomReportCredentials("username", "password", "domain/Ip");
                serverReport.ReportServerUrl =
                   new Uri("http://xx.xxx.xxx.222/ReportServer_MSSQLSERVER2016");
                serverReport.ReportPath = "/Reports/Report3";
                ReportViewer1.ServerReport.Refresh();

Here is a good link about Passing Credentials to Sql Report Server 2008 Passing Credentials to Sql Report Server 2008 That's all you need to do. just drag a report viewer and authenticate the user and that's it. hopefully this is helpful for you.

Enlighten_me
  • 56
  • 1
  • 5