Is it the same database type just a different db location for each report? If so, this is not difficult.
I assume that your program knows which database to connect the report to. Using the ReportDocument object model, here's the code we use for this:
ConnectionInfo connectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
connectionInfo.ServerName = myDB;
connectionInfo.UserID = myUser;
connectionInfo.Password = myPassword;
// set report connection for main report
SetDBLogonForReport(connectionInfo, crReport, qServer);
// set report connection for any subreports
SetDBLogonForSubreports(connectionInfo, crReport, qServer);
---------------------
private void SetDBLogonForReport(ConnectionInfo connectionInfo,
ReportDocument reportDocument, string qServer)
{
Tables tables = reportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogonInfo);
}
}
---------------------
private void SetDBLogonForSubreports(ConnectionInfo connectionInfo,
ReportDocument reportDocument, string qServer)
{
Sections sections = reportDocument.ReportDefinition.Sections;
foreach (Section section in sections)
{
ReportObjects reportObjects = section.ReportObjects;
foreach (ReportObject reportObject in reportObjects)
{
if (reportObject.Kind == ReportObjectKind.SubreportObject)
{
SubreportObject subreportObject = (SubreportObject)reportObject;
ReportDocument subReportDocument =
subreportObject.OpenSubreport(subreportObject.SubreportName);
SetDBLogonForReport(connectionInfo, subReportDocument, qServer);
}
}
}
}
This only works for reports that are connecting to the same type of database as the one the report was designed with - all SQL Server, all Oracle, etc. You can't run one time with SQL Server and another on Oracle using this code.
-Dell