This is a migrated thread and some comments may be shown as answers.

Can ReportViewer use NeedDataSource?

11 Answers 417 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Clint
Top achievements
Rank 1
Clint asked on 08 Sep 2016, 10:52 PM

I've created a report in Designer, and am trying to pass the data within the ASPX code behind to the ReportViewer. This page acts as if this event exists, but my ReportViewer object doesn't have it listed in intellisense. The ReportViewer object doesn't even seem to have a DataSource object even though I see it mentioned here.

The only details that I can tell apply to what I'm using are How to: Set ReportSource for Report Viewers and ReportViewer Members. I see that I can set the designer file and the parameters, but nothing about passing the connection string or select statement/SPROC.

So can you only use Data Connections within Telerik Report Designer, and not pass them from the code behind, when using "HTML5 ASP.NET Web Forms Viewer."

11 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 09 Sep 2016, 03:53 PM
Hi Clint,

Please check the information in http://www.telerik.com/support/kb/reporting/details/how-to-display-a-report-via-instancereportsource-in-the-html5-viewer (How to display a report via InstanceReportSource in the HTML5 Viewer), and the example of modifying a report at run-time here.


Let us know if you need further help.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Clint
Top achievements
Rank 1
answered on 09 Sep 2016, 10:12 PM

Looking at http://www.telerik.com/support/kb/reporting/details/changing-the-connection-string-dynamically-according-to-runtime-data

It says: "If you intend to use the above code for modifying reports displayed by an HTML5 Viewer, the code must be placed in the Resolve method of a custom resolver used by the Reporting REST service."

Is it not possible to change the connection string used by a TRDX report in the code behind of the report's ASPX? I'm looking to have a pretty static report with two parameters that I will pass from session, and the connection string be determined at that same time. I'd rather keep with the same model we're using for filling RadGrid's if possible. I don't think we'd be comfortable having our connection strings saved in the reports.

0
Stef
Telerik team
answered on 10 Sep 2016, 02:26 PM
Hi Clint,

The page with the viewer is not suitable as the HTML5 Viewer (including the HTML5 WebForms wrapper) is a client-side widget, where reports are resolved, processed and rendered on the server.

The HTML5 Viewer sends messages (string descriptions) what should happen on the server, and it is the Reporting REST service that reads the message, creates objects on the server and delivers content to the viewer. This is the reason to use a custom resolver for the Reporting REST service.


About the approach illustrated in http://www.telerik.com/support/kb/reporting/details/changing-the-connection-string-dynamically-according-to-runtime-data, the report is deserialized at run-time and the modified Telerik.Reporting.Report object exists only in memory. The TRDX file is not modified actually.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Clint
Top achievements
Rank 1
answered on 14 Sep 2016, 05:57 PM

I have a reporting host started using these instructions http://docs.telerik.com/reporting/telerik-reporting-rest-host-http-service-using-self-hosting

I'm using a custom resolver and have a couple of questions:
Can I use the UriReportSource for grabbing the TRDP file as in http://docs.telerik.com/reporting/standalone-report-designer-display-report-viewer#display-trdp-in-a-report-viewer if I do it seems that class doesn't have a member for the DataSource. So I wouldn't be able to set it manually on the host. For that reason I'm suspecting I need to stick with Telerik.Reporting.Report but I'm not sure how to grab a TRDP file with it. I've only been able to find examples of deserializing XML.

Will I need to set the parameters on the reportInstance in the host? Will these still be passed by the client using something like:

reportSource: { report: "Dashboard.trdp", parameters: { CultureID: "en } }

0
Clint
Top achievements
Rank 1
answered on 14 Sep 2016, 07:26 PM

I think I found out how to deal with the parameters within my custom Resolve method.

 

http://www.telerik.com/forums/customreportresolver-where-are-the-parameters#ul7z7CLyDUKscWKkkkFTfQ

 

This thread talks about passing a JSON string where the report name would normally be. So that's what I'll try to do.

 

All I need to know now is the best way to retrieve my TRDP report as a Telerik.Reporting.Report

 

Thanks!

0
Stef
Telerik team
answered on 15 Sep 2016, 11:44 AM
Hello Clint,

Please double check the mentioned resources. They elaborate on that approach where you can send custom information in string format to the server, where the string is handled in a custom resolver.
  • http://www.telerik.com/support/kb/reporting/details/how-to-display-a-report-via-instancereportsource-in-the-html5-viewer
  • Example - http://www.telerik.com/forums/changing-a-parameter's-datasource-connection-string-at-runtime#Ynj-MZ0ZZEyVdfGGA-G6fA

The string can be submitted through the viewer's reportSource.report string (this string gets into the custom resolver's Resolve method). The string can be "Sample.trdp-123".
Let assume you use the HTML5 viewer's WebForms wrapper:
protected void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               var clientReportSource = new Telerik.ReportViewer.Html5.WebForms.ReportSource();
               clientReportSource.IdentifierType = IdentifierType.CustomReportSource;
               clientReportSource.Identifier = "SampleReport.trdp-123";
               reportViewer1.ReportSource = clientReportSource;
           }
       }
If you use a TypeReportSource, the submitted string will be the TypeReportSource.TypeName; in the case of an UriReportSource - the UriReportSource.Uri string.


In the custom resolver's Resolve method you can add logic like:
  public class MyResolver : Telerik.Reporting.Services.Engine.IReportResolver
    {
        public Telerik.Reporting.ReportSource Resolve(string report)
        {
            var IRS = new InstanceReportSource() { ReportDocument = null };
 
            var receivedClientValues = report.Split('-');
 
            if (receivedClientValues[0].ToLower() == "samplereport.trdp")
            {
               //unpackage
               var reportPackager = new ReportPackager();
               //map the file on the server if needed
               var reportsPath = HttpContext.Current.Server.MapPath("~/Reports/");
               using (var sourceStream = System.IO.File.OpenRead(reportsPath +receivedClientValues[0]))
                  {
                      var reportInstance = reportPackager.Unpackage(sourceStream);
                
                    //display the custom report via InstanceReportSource
                     IRS.ReportDocument = reportInstance;
                   }              
            }
            return IRS;
        }
}
The above code snippet illustrates a custom resolver that can be used by a Reporting RESt service. The code includes the recommended approach for getting a Telerik.Reporting.Report object from TRDP file - http://docs.telerik.com/reporting/report-packaging-trdp.


Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Clint
Top achievements
Rank 1
answered on 26 Sep 2016, 11:58 PM

Thank you! I believe I'm very close to having my project working. I'm able to get a report to run through my WebAPI service and ASP.NET page, but only if the datasource is set within the report. If I strip it out and try to set in my custom resolver, then I get:

An error has occurred while processing Table 'table1':
ExecuteReader: CommandText property has not been initialized

I have checked through the debugger and I am in fact changing the DataSource on table1, before the ReportInstance is assigned to Telerik.Reporting.InstanceReportSource.ReportDocument. When the same connection string is set within the report and I skip the reassignment steps in the resolver, the report runs perfectly. If I set the table to have no DataSource within the report, and attempt to modify it in the Resolver, the report comes up empty, but without error.

0
Accepted
Stef
Telerik team
answered on 28 Sep 2016, 09:47 AM
Hello Clint,

The error message is bubbled from the attempt to get data for the report. Based on the message (stackoverflow and social msdn) it must be related to the logic of the data-retrieval method or the sequence of setting properties for the a command that will be executed by a reader

Please debug the data-retrieval method and verify the Table.DataSource property is updated correctly.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Clint
Top achievements
Rank 1
answered on 29 Sep 2016, 08:19 PM

The issue came from the connection saved in the report using Integrated Security which wouldn't work. What's odd is that if I place the complete connection string within the report's data source at design time, it works. But if I try to set that same connection string at runtime, it doesn't. I can verify that I am setting the Table.DataSource, the same one that is being used in the report. I know because in the debugger I'm able to find where the design set string is, then I try to change it. The reportInstance object seems to carry the change but then it doesn't work. What's odd is that the parameters and page settings work, just not the connection string. So right now for testing I'm having to leave the connection string within the report, but I will need to be able to set it here in the Resolver before I can go to production.

Here is how I am trying to set it in code. Thanks!

Telerik.Reporting.ReportPackager reportPackager = new Telerik.Reporting.ReportPackager();
 
var reportsDir = System.IO.Path.GetFullPath(@"..\..\api\reports\");
using (var sourceStream = System.IO.File.OpenRead(reportsDir + reportName))
{
   Telerik.Reporting.Report reportInstance = reportPackager.Unpackage(sourceStream);
 
   Telerik.Reporting.SqlDataSource conn = new Telerik.Reporting.SqlDataSource()
   {
      ConnectionString = string.Format(Properties.Settings.Default.ConnectionString,
                             Properties.Settings.Default.Server,
                             Properties.Settings.Default.Catalog,
                             Properties.Settings.Default.Username,
                             Properties.Settings.Default.Secret
                            ),
      SelectCommand = @"QUERY",
      SelectCommandType = Telerik.Reporting.SqlDataSourceCommandType.Text
   };
 
   (reportInstance.Items.Find("table1", true)[0] as Telerik.Reporting.Table).DataSource = conn;
   reportInstance.ReportParameters["param1"].Value = param1;
   reportInstance.ReportParameters["param2"].Value = param2;
   reportInstance.PageSettings.Landscape = true;
   IRS.ReportDocument = reportInstance;
}

0
Accepted
Clint
Top achievements
Rank 1
answered on 30 Sep 2016, 09:06 PM

I found my issue. I was making the assumption that my report parameters would still get tied to the query when assigned at run time. In the report I had them associated with the sql parameters as 

= Parameters.param1.Value

Once I added the parameters to the connection, all is working.

conn.Parameters.Add("@param1", System.Data.DbType.Int16, param1);
conn.Parameters.Add("@param2", System.Data.DbType.Int16, param2);

0
Stef
Telerik team
answered on 04 Oct 2016, 04:24 PM
Hi Clint,

Thank you for this update. I am glad to hear the issue is resolved.

indeed the code reassigns the data item's DataSource and the original data source's Parameters collection will be lost. In case parameters are the same, you can copy the Parameters collection in the new data source component's Parameters collection.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Clint
Top achievements
Rank 1
Answers by
Stef
Telerik team
Clint
Top achievements
Rank 1
Share this question
or