Hi Ludek,
Thanks for reply. I apologise for not specifying enough details.
I have report A and B.
Report A doesn't not have any subreports.
While designing report A, I have specified servername as "SERVER01".
Now, in code I am using SetDataSource() method to set DataSet as datasource for report A.
As we know if we use SetDataSource() method, crystal ignores connection details.
It just try to map the table name from connection or datasource.
E.g. if report A had table name "TABLE_01", crystal will try to locate "TABLE01" either from database or datasource. In above details I have used SetDataSource() method by passing a DataSet, so crystal tries to find "TABLE01" in this DataSet. If it finds it will read the data and display in report.
For Report A I also tried using ApplyLogonInfo() method with different server on database.tables; it worked. In short Report A worked for me in both the scenarios.
1. Using SetDataSource()
2. Using ApplyLogOnInfo() of reportA.Database.Table[0];
So far I am fine.
--------------------------------------------------------------------------------------------------------------------------------------------------
Now next case:
Report B with some subreports B1,B2,B3.
While designing B,B1,B2,B3; I have specified servername as "SERVER01".
Report B having table name "TABLE02"
Now, here I am trying to use same 2 techniques as I did above for Report A.
Instead of relying on connection in B, I will use SetDataSource() method to pass DataSet 'ds' only for B not for B1,B2,B3.
DataSet ds = GetDataFromService();
reportB.SetDataSource(ds);
Here I am applying different logon info with SERVER02 for subreports B1,B2,B3 as shown below:
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "SERVER02";
connectionInfo.UserID = "ABC";
connectionInfo.Password = "HELLOWORLD";
TableLogOnInfo info = new TableLogOnInfo();
info.ConnectionInfo = connectionInfo;
for (int i = 0; i < reportB.Subreports.Count; i++)
{
var subReport = reportB.Subreports[i];
for (int j = 0; j < subReport.Database.Tables.Count; j++)
{
subReport.Database.Tables[j].ApplyLogOnInfo(info);
}
}
As I am not going to call SetDataSource() method of subreports then those reports will try to read data through connection.
Finally, I am trying to export reportB to pdf as:
doc.ExportToDisk(ExportFormatType.PortableDocFormat, "C:\\rpt_2.pdf");
This doesn't work. It throws an exception DataSourceException.
An unhandled exception of type 'CrystalDecisions.CrystalReports.Engine.DataSourceException' occurred in CrystalDecisions.ReportAppServer.DataSetConversion.dll
Additional information: Failed to load database information.
Error in File report_b{5E579755-5CC4-4F00-9EE9-B878D685EB9F}.rpt:
The error happens for reportB which is parent for B1,B2,B3.
Can you help me to solve it? Thanks.