Setting DataSource for PageReports at runtime

Posted by: mdynna on 16 May 2022, 4:27 pm EST

    • Post Options:
    • Link

    Posted 16 May 2022, 4:27 pm EST

    Hi there,

    I’ve found a few old topics about this so I wanted to see if anything has changed since 2014/2015 when those topics were originally posted.

    We need to able to set the Connection String of report’s DataSource at run-time. The shared data source functionality looks promising as it saves the connection string in an XML file that is almost identical to the one our application uses to store connection information. Is there an event that fires or a function that can be overridden when that Shared data source is loaded so that I can redirect where/how the reports get that connection string information?

    Alternatively, I see how the LocateDataSource event works for a “base” report, but does that work for “drill through” reports that are launched via the JumpToReport action? I haven’t yet been able to find the run-time instance of that “jump to” report so I can bind the Handler to the Event.

  • Posted 17 May 2022, 8:51 am EST

    Hello Mark,

    It is not possible to edit the shared data source properties through the report object. You would have to edit the SharedDataSource file before the report is loaded. The LocateDataSource alternative should be the way to go. The reporting engine raises the LocateDataSource event when it needs input on the data to use. Also, For Drill Through reports the same LocateDataSource event is called when the user jumps to a report. You can add conditions in the LocateDataSource event and assign args.Data based on args.DataSet.Name or args.Report.Name.

    Please refer to the following lines of code:

    ```
    

    report1.Document.LocateDataSource += Document_LocateDataSource; //Only set for first report

    private void Document_LocateDataSource(object sender, LocateDataSourceEventArgs args)

    {

    if( args.Report.Name == “Report1”)

    {

    if (args.DataSet.Name == “Categories”)

    {

    args.Data = CategoriesTable;

    }

    }

    if( args.Report.Name== “Report2”)

    {

    if (args.DataSet.Name == “Products”)

    {

    args.Data = ProductsTable;

    }

    }

    }
    
    
    For more information on this please refer to the following page of our documentation:
    
    https://www.grapecity.com/activereportsnet/docs/latest/online/bind-page-reports-to-a-datasource.html
    
    Regards,
    
    Akshay
  • Posted 17 May 2022, 3:44 pm EST

    Ok, I have that part working.

    When a Page Report uses an Object provider, is it expected that the LocateDataSourceEventArgs has no Parameters? I entered the parameters in the JumpToReport action, but they seem to “disappear” after compiling.

  • Posted 19 May 2022, 2:51 am EST

    Hello Mark,

    args.Parameter gets the values from the target report’s DataSet parameter value. If you need to find the Parameter DrillThrough action in LocateDataSource, then just add the dataset parameter(the parameters tab in the dataset editor) to the dataset in the target report and bind this dataset parameter with the report parameter, so you will have access to the parameter value via args.Parameters collection of the LocateDatasource event handler.

    Please refer to the attached sample.

    Regards,

    Akshay

    RuntimeDataRdlApplication.zip

  • Posted 27 May 2022, 11:46 am EST - Updated 30 September 2022, 4:25 pm EST

    So this has reveal something new and interesting. There seems to be something wrong with Active Reports in my IDE. The setup of your report makes sense, at that is something that I have tried before but I couldn’t get it to work consistently and now I think I know why.

    For whatever reason, when I go to view the Textbox “actions” window, it automatically strips out the parameters passed to the “jump to” report. I can see because the instant I bring up that window, the file shows as changed (prompting a save). I did a diff against a backup that I made and sure enough, the parameter part of the file has been removed.

    If the text box action is set to “none” I can add the “Jump To Report” action and set those parameters. If I then go right back into that window the Parameters are now all gone.

    Any ideas on how to correct this? I’m using VS 2019 Enterprise, Version 16.11.15.

  • Posted 30 May 2022, 8:06 am EST

    Hello Mark,

    I was unable to replicate this behavior on my end using Visual Studio 2019 Professional Edition 16.11.15. Please try reinstalling ActiveReports 16. If the issue still persists let us know what exact version of ActiveReports 16.x.x you have installed on your system.

    Regards,

    Akshay

  • Posted 30 May 2022, 3:27 pm EST

    We are using Active Reports 15, version 15.1.3. I will try reinstalling.

  • Posted 31 May 2022, 12:29 am EST

    Hello Mark,

    Please also test with ActiveReports 15 SP3. You can download other versions of ActiveReports 15 from the following page.

    https://www.grapecity.com/controls/activereports/download-version-history

    Regards,

    Akshay

  • Posted 31 May 2022, 12:37 pm EST

    Installing Active Reports 15.3 resolves the issue, even with project references still using 15.1.

    I have also found the resolution to my original question. By using LocateDataSource and the args.Parameters collection I can load the proper data for the Drill Through reports.

    Thanks for your help!

  • Posted 1 June 2022, 6:16 am EST

    Hey Mark,

    >> Installing Active Reports 15.3 resolves the issue, even with project references still using 15.1.

    This is because the ActiveReports Visual Studio extension which is used to open the Designer at design time references to the installed version of ActiveReports 15 not the one which the application is using at runtime. As your issue was fixed after installing the higher version of ActiveReports 15, the issue seems to be with the integrated designer of v15.1 and must have been fixed in a later update.

    >> I have also found the resolution to my original question. By using LocateDataSource and the args.Parameters collection I can load the proper data for the Drill Through reports.

    I am glad to know that the issue is resolved.

    Regards,

    Akshay

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels