I have a report made with Crystal Reports 2008 that I need to deploy a production system which means that I need to be able to change the database connection at runtime. Th
protected void Page_Load(object sender, EventArgs e)
{
try
{
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
cryRpt.Load(@"D:\tem\WebAppReport\WebAppReport\CrystalReport1.rpt");
crConnectionInfo.ServerName = "misserver";
crConnectionInfo.DatabaseName = "testAccountability_data";
crConnectionInfo.UserID = "RW";
crConnectionInfo.Password = "RW";
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in cryRpt.Database.Tables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
CrystalReportViewer1.ReportSource = cryRpt;
CrystalReportViewer1.RefreshReport();
}
catch
{
}
}