How do I change a Crystal Report's ODBC database connection at runtime?

前端 未结 6 2066
暗喜
暗喜 2020-11-30 10:35

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

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-30 11:18

    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
                {
                }
    
    
    
    
    
    
            }
    

提交回复
热议问题