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

Change Connection String at Runtime on Drillthrough Report

3 Answers 99 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Don Tompkins
Top achievements
Rank 1
Don Tompkins asked on 07 Dec 2012, 08:33 PM
Hello, I am trying to use the reportViewer component in my asp.net application. Our requierments are as follows:

  • Need to use trdx files so our clients can create their own reports and upload them through our application.
  • Need to change the datasource to the trdx files at runtime to connect to the proper database based on user.
  • A couple of reports will require drillthrough capabilities and the drillthrough files will also require the datasource to be set at runtime.

I found a sample listed by Erwin in your forum (Change Connection String for Reports designed in the Standalone Designer) to change the connection string at runtime and it is working fine for displaying the reports, however I am wondering how I will be able to change it in the drillthrough report.

Any documentation on changing the connection string at runtime for the drillthrough report would be appreciated.

Regards,

Don Tompkins

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 11 Dec 2012, 04:26 PM
Hi Don,

Is my colleague suggestion from the referenced thread applicable for your scenario:

In the standalone report designer, when you use SqlDatasource component, you're asked to save the connectionString with a desired name. This name is the name of the connectionString, so basically you can have a connectionString with the same name attribute in your application config file (app.config) and the SqlDatasource component would handle the binding automatically.

If you need more flexibility in applying the connection strings our suggestion is to utilize an user function to update the connection strings as shown in the following example:

public static SqlDataSource UpdateConnectionString(SqlDataSource dataSource)
{
    dataSource.ConnectionString = "New Connection String";
    return dataSource;
}
Once you add the user function as elaborated in the Extending Report Designer help article, you have to add the following binding:
 Property path Expression
DataSource  = MyUserFunctionsNamespace.UpdateConnectionString(ReportItem.ItemDefinition.DataSource)

This binding will get the current report item data source component, execute the user function and bind the current report item to the updated data source component.

All the best,
Peter
the Telerik team

HAPPY WITH TELERIK REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

0
Don Tompkins
Top achievements
Rank 1
answered on 17 Dec 2012, 05:31 PM
Hello, I'm not sure I am following your suggestion. I do not need to change datasource in the report designer. I need to change the datasource for a drillthrough report in ReportViewer component that I am using in my ASP.NET application.

Can you please let me know if this is possible?

Our intentions is to use standard reports with several of our clients on a hosted site. They will all use the same reports under our ASP.NET application, but the source of the data will be unique for each client, so we need to change the datasource at runtime based on our clients configuration.

Thank you very much for your assistance.

Don Tompkins
0
Peter
Telerik team
answered on 18 Dec 2012, 05:27 PM
Hello Don,

Generally the user functions are working in the context of the running application in your case when viewing the reports in the Web report viewer this is the ASP.NET application. However while designing the reports this is the report designer. In this line of thoughts you can provide a dummy user function for the report designer but in the ASP.NET application you can reference an assembly with user function that modifies the connection string. With this approach you can handle even drill through reports. You have only to instruct your user to set up the required binding or prior to saving the reports on the server, deserialize the reports set up the binding and serialize the reports again.

If you still experience difficulties please send us your code for changing the connection string and we will provide you an user function that can handle the same scenario.

Greetings,
Peter
the Telerik team

HAPPY WITH REPORTING? Do you feel that it is fantastic? Or easy to use? Or better than Crystal Reports? Tell the world, and help fellow developers! Write a short review about Telerik Reporting and Telerik Report Designer in Visual Studio Gallery today!

Tags
General Discussions
Asked by
Don Tompkins
Top achievements
Rank 1
Answers by
Peter
Telerik team
Don Tompkins
Top achievements
Rank 1
Share this question
or