更改Crystal Reports for .NET中的数据库

时间:2009-01-23 08:29:54

标签: asp.net crystal-reports

我有一个问题,这里有完美的描述(http://www.bokebb.com/dev/english/1972/posts/197270504.shtml):

情景:

Windows智能客户端应用程序和Windows的CrystalReportViewer。 使用ServerFileReports通过集中和断开连接的文件夹位置访问报告。

当访问针对DB_DEV设计的报告并尝试通过CrystalReportViewer更改其LogonInformation以指向DB_UAT时,它似乎永远不会实际使用更改的信息。

它总是违反DB_DEV信息。

知道如何更改ServerFileReport的数据库连接和登录信息????

Heres代码:

来自主持人:



// event that fires when the views run report button is pressed
private void RunReport(object sender, EventArgs e)
{
this.view.LoadReport(Report, ConnectionInfo);
}

protected override object Report
{
get
{
ServerFileReport report = new ServerFileReport();
report.ObjectType = EnumServerFileType.REPORT;
report.ReportPath = @"\Report2.rpt";
report.WebServiceUrl = "http://localhost/CrystalReportsWebServices2005/ServerFileReportService.asmx";
return report;

}
}
private ConnectionInfo ConnectionInfo
{
get
{
ConnectionInfo info = new ConnectionInfo();
info.ServerName = servername;
info.DatabaseName = databasename;
info.UserID = userid;
info.Password = password;
return info;
}
}

ON THE VIEW WITH THE CRYSTAL REPORT VIEWER:

public void LoadReport(object report, ConnectionInfo connectionInfo)
{
viewer.ReportSource = report;
SetDBLogon(connectionInfo);
}

private void SetDBLogon(ConnectionInfo connectionInfo)
{
foreach (TableLogOnInfo logOnInfo in viewer.LogOnInfo)
{
logOnInfo.ConnectionInfo = connectionInfo;
}
}

有谁知道如何解决这个问题?

3 个答案:

答案 0 :(得分:0)

我知道这不是您正在寻找的程序化答案,但是:

有一点可以帮助解决这类问题,而不是直接创建连接到数据库的报表,但首先要为Crystal Reports创建“数据字典”(这在报表设计器中完成)。然后将所有报告链接到此字典,该字典将字段映射到正确的数据库。

通过这种方式,您只有一个地方可以更改所有报告的数据库架构/连接信息。

此外,在报表设计器中将报表设置为不缓存结果(抱歉,我不记得确切的选项)。报告可以包含或不包含初始结果。

答案 1 :(得分:0)

在CrystalReportViewer对象中,您应该设置

AutoDataBind="true"

答案 2 :(得分:0)

您是否必须浏览报告的所有“databaseTable”对象才能重定向相应的连接?你会发现here我的VB版本的'数据库切换'问题......