在我的案例中,如何在Asp.Net C#中为Crystal Report创建动态连接字符串?

时间:2018-07-08 07:16:26

标签: asp.net crystal-reports

我有多个iis,所有iis网页都连接到不同的数据库。我的Crystal Reports太多了,一旦将它上载到所有多个iis,它就必须连接到相应的数据库。

我不知道要在水晶报表中创建连接字符串。

这是我的ReportViewer代码

protected void CrystalReportViewer1_Init(object sender, EventArgs e)
    {
        ReportDocument _rdStudents = new ReportDocument();

        Trace.Write("/CrystalReportFiles/RMS/Inventory/");
        string reportPath = Server.MapPath("~" + Request.QueryString["filename"].ToString());

        _rdStudents.Load(reportPath);
        CrystalReportViewer1.ReportSource = _rdStudents;
    }

如何在此处制作连接字符串。我看到了其中的一些link。但是我不明白这一点。

1 个答案:

答案 0 :(得分:2)

关注此事。

TableLogOnInfos TableLogOnInfos = new TableLogOnInfos();
TableLogOnInfo TableLogOnInfo = new TableLogOnInfo();
ConnectionInfo ConnectionInfo = new ConnectionInfo();
Tables Tables;
ConnectionInfo.ServerName = "ServerName";
ConnectionInfo.DatabaseName = "Database";
ConnectionInfo.UserID = "UserId";
ConnectionInfo.Password = "Password";

ReportDocument _rdStudents = new ReportDocument();
Trace.Write("/CrystalReportFiles/RMS/Inventory/");
string reportPath = Server.MapPath("~" + Request.QueryString["filename"].ToString());

_rdStudents.Load(reportPath);

Tables = _rdStudents.Database.Tables;
    foreach (CrystalDecisions.CrystalReports.Engine.Table table in Tables)
    {
        TableLogOnInfo = table.LogOnInfo;
        TableLogOnInfo.ConnectionInfo = ConnectionInfo;
        table.ApplyLogOnInfo(TableLogOnInfo);
    }
 CrystalReportViewer1.RefreshReport();
 CrystalReportViewer1.ReportSource = _rdStudents;