我有8个报告使用完全相同的代码来设置报告数据源,其中5个报告可以工作并且能够指向生产环境。 3个报告的其余部分,我已经运行并重新运行数据库验证和数据库更新,但是当我在生产中运行这些报告时,它们会从DEV环境中恢复数据。
以下是我的数据源设置方式。 我在所有8个水晶报告中调用存储过程。 我已经做了非常详细的调试并验证了数据源数据正在获取正确的信息,因此缺少了。
string database = ConfigurationManager.AppSettings[env + "Database"].ToString();
string server = ConfigurationManager.AppSettings[env + "Server"].ToString();
CrystalReportViewer1.ParameterFieldInfo = fields;
rptDoc.Load(Server.MapPath(report));
ConnectionInfo connectionInfo = Reports.GetConnectionInfo(server, database, "userID", "password");
//connectionInfo.Attributes = attributes;
connectionInfo.Type = ConnectionInfoType.SQL;
SetDBLogonForReport(connectionInfo, env);
CrystalReportViewer1.ReportSource = rptDoc;
private void SetDBLogonForReport(ConnectionInfo oConnectionInfo, string env)
{
try
{
TableLogOnInfos oTableLogOnInfos = CrystalReportViewer1.LogOnInfo;
string[] sparams = new string[]{
};
foreach (CrystalDecisions.CrystalReports.Engine.Table oTable in rptDoc.Database.Tables)
{
if (oTable.LogOnInfo.ConnectionInfo.ServerName == oConnectionInfo.ServerName)
{
TableLogOnInfo oTableLogOnInfo = oTable.LogOnInfo;
oTableLogOnInfo.ConnectionInfo = oConnectionInfo;
oTable.ApplyLogOnInfo(oTableLogOnInfo);
// oTable.Location = String.Format( "{0}.dbo.{1}", oConnectionInfo.DatabaseName, oTable.Name );
bool b = oTable.TestConnectivity();
if (!b)
{
invokeErrorLogger(sparams, env);
}
}
}
}
catch
{
throw;
}
}
答案 0 :(得分:1)
有效的报告已经指向您的prod服务器。如果报告中存储的服务器与您尝试设置的服务器名称匹配,则仅应用登录凭据。更改为以下内容:
// Clear existing connection info first
rptDoc.DataSourceConnections.Clear();
foreach (CrystalDecisions.CrystalReports.Engine.Table oTable in rptDoc.Database.Tables)
{
var oTableLogonInfo = oTable.LogonInfo;
oTableLogonInfo.ConnectionInfo = oConnectionInfo;
oTable.ApplyLogOnInfo(oTableLogonInfo);
bool b = oTable.TestConnectivity();
if (!b)
{
invokeErrorLogger(sparams, env);
}
}