I'm having an issue when trying to get data from a report document in Visual Studio 2010 using C#/ASP.NET.
The error returned is:
System.Runtime.InteropServices.COMException (0x800002CD): Failed to load database information.
Error in File Rpt_Invoice_Email_Silvers 8992_12168_{C7B8866B-E3F0-4F90-99EC-A71983CF6923}.rpt:
Failed to load database information.
at CrystalDecisions.ReportAppServer.Controllers.RowsetControllerClass.CreateCursor(ISCRGroupPath GroupPath, RowsetMetaData MetaData, Int32 Reserved)
at CrystalDecisions.CrystalReports.Engine.ReportDocument.hasRecords()}
I'm not looking to view it through a report viewer, just trying to get the data, then export it to XML. It's an older, existing report file with subreports, formulas, tables and COM objects as the stored procedures. When I saved the .rpt file in VS2010, i was asked to upgrade it, which i did. The datasource location has been changed from an ODBC (RDO) connection(32 bit) to a OLE DB (ADO) connection (SQL 2012)
The current CR runtime engine is version 13 (64 bit). The CR for Visual Studio is version 13 as well (64 bit).
The code below is what is used to populate the report. Only 2 parameters are required to preview the report. The preview works fine though:
ReportDocument report = new ReportDocument();
string sPathToReport = HttpContext.Current.Server.MapPath("~/reportdocuments/Rpt_Invoice_Email_Silvers.rpt");
report.Load(sPathToReport);
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName = ConfigurationManager.AppSettings["strServer"];
crConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["strDBase"];
crConnectionInfo.UserID = ConfigurationManager.AppSettings["strUID"];
crConnectionInfo.Password = ConfigurationManager.AppSettings["strPWD"];
foreach (ReportDocument subReport in report.Subreports)
{
Tables SubTables = subReport.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table SubTable in SubTables)
{
crtableLogoninfo = SubTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
SubTable.ApplyLogOnInfo(crtableLogoninfo);
}
}
Tables CrTables = report.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
ParameterFieldDefinitions parameterList = report.DataDefinition.ParameterFields;
for (int i = 0; i < parameterList.Count; i++)
{
if (parameterList[i].IsLinked())
{
}
else if (parameterList[i].ParameterFieldName == "CEOInvoiceID")
{
report.SetParameterValue(i, Convert.ToInt32(invoiceId));
}
else if (parameterList[i].ParameterFieldName == "CEOCustomerID")
{
report.SetParameterValue(i, Convert.ToInt32(customerId));
}
else
{
if (parameterList[i].DefaultValues.Count > 0)
{
report.SetParameterValue(i, parameterList[i].DefaultValues[0]);
}
}
}