如何在Asp.NetC #中为水晶报表创建动态连接字符串?

7hiiyaii  于 2023-08-08  发布在  .NET
关注(0)|答案(1)|浏览(103)

我有多个iis,所有的iis网页连接不同的数据库。我有太多的水晶报表,一旦我上传到所有多个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。但我不明白。

x7rlezfr

x7rlezfr1#

跟着这个

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;

字符串

相关问题