Urgent: Crystal reports in c# setting database server dynamicalLY

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

I have a few reports in crystal reports.net, and our database the
application works with is selected at startup (development, live,test).. but
the reports were all designed with the development database (all db's have
the same structure) so they are pulling data all the time from the
development db...well i need the reports to run based on what database was
selected at the application load... how do you go about changeing the
database on a report file at runtime? thanks
 
Hi Brian,

See the code below, you use ConnectionInfo for that

TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
reportDocument1 = new OpenRecords();

ConnectionInfo crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName = "127.0.0.1";
crConnectionInfo.DatabaseName = "CTP";
crConnectionInfo.UserID = "CTPWeb";
crConnectionInfo.Password = "CTPApp";
foreach (CrystalDecisions.CrystalReports.Engine.Table table in
reportDocument1.Database.Tables)
{
TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
crTableLogonInfo.TableName = table.Name;
crTableLogonInfo.ConnectionInfo = crConnectionInfo;
crTableLogonInfos.Add( crTableLogonInfo);
table.ApplyLogOnInfo( crTableLogonInfo);

}
CrystalReportViewer1.LogOnInfo = crTableLogonInfos;
CrystalReportViewer1.ReportSource = reportDocument1;

Cheers,
 
Back
Top