Replace the database connection for the report and all subreports

Is there a way to change the location of the data source for the report and all its subreports without opening them manually?

+7
crystal-reports
source share
5 answers

This is how I make my connections at runtime. I get connection information from the configuration location.

#'SET REPORT CONNECTION INFO For i = 0 To rsource.ReportDocument.DataSourceConnections.Count - 1 rsource.ReportDocument.DataSourceConnections(i).SetConnection(crystalServer, crystalDB, crystalUser, crystalPassword) Next For i = 0 To rsource.ReportDocument.Subreports.Count - 1 For x = 0 To rsource.ReportDocument.Subreports(i).DataSourceConnections.Count - 1 rsource.ReportDocument.OpenSubreport(rsource.ReportDocument.Subreports(i).Name).DataSourceConnections(x).SetConnection(crystalServer, crystalDB, crystalUser, crystalPassword) Next Next 
+6
source share

If you just do it as a one-time deal, my suggestion may not help. But, if you frequently change data sources, this can be useful.

Disclaimer: I have not worked with Crystal since version 9.0, so I do not know if they have improved on this. I have always used UDL files . Basically, it is a pointer to a data source. Customize your report to point to the UDL, and the UDL points to the data source. If the source is changing, just update the UDL.

This is incredibly useful if you have multiple reports. Updating only one file when changing the server.

+2
source share

The related subheadings (at least in CR XI) use the main source of the report data - apparently your report is already set up so that you don't need an option?

+1
source share

@Unsliced. I think that the problem he is facing is when you make a crystal report that someone developed against another database and you update it in Crystal Reports XI, you need to make a Datasource for each field, including in subreports. If you simply change the source at the top level of the report, this often leads to errors. (I think this is a known issue in Crystal Reports).

+1
source share

I assume you are talking about .rdl files from Reporting Services? (If not, my answer may be wrong)

They are basically just XML, so you can load each of them and execute an XPath query to get the node that contains the data source and update it.

-one
source share

All Articles