1711050 - Error: Database Connector Error when passing several parameters to Crystal Reports using the VS .NET SDK

SAP Knowledge Base Article - Public

1711050 - Error: Database Connector Error when passing several parameters to Crystal Reports using the VS .NET SDK

Symptom

  • When more than one parameter is set in code, the following exception is thrown:

Exception: CrystalDecisions.CrystalReports.Engine.DataSourceException:
Database Connector Error: ' [Database Vendor Code: 257 ]' Error in File
cspRpt_REDACTED_Qry_Rate_Per_Month_Wk {DA3493B8-490B-40AB-A4DE- D1580716B30C}.rpt: Database Connector Error --->
System.Runtime.InteropServices.COMException: Database Connector Error: '[Database Vendor Code: 257 ]'
Error in File cspRpt_REDACTED_Qry_Rate_Per_Month_Wk {DA3493B8-490B-40AB-A4DE-D1580716B30C}.rpt: Database Connector Error at
CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) at
CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportR equestContext reqContext)

Environment

  • Crystal Reports for Visual Studio 2010
  • Visual Studio 2010
  • MS SQL 2005 \ 2008
  • Upgrade from Crystal Reports XI R2 (11.5) to Crystal Reports for Visual Studio 2010 (13.x)

Reproducing the Issue

  • Use the following code to set more than one parameter:
private void ReportDocumentSetParameters()
        {
             SetCrystalParamsToNull(m_ReportDocument);
             SetCrystalParam(m_ReportDocument, "@AA", "100");
             SetCrystalParam(m_ReportDocument, "@BB", "2");
             SetCrystalParam(m_ReportDocument, "@CC", null);
      }

Cause

  • Previous to CRVS2010, crParamField.ApplyCurrentValues checked internally and automatically to determine where a particular parameter belongs
  • In CRVS2010,  crParamField.ApplyCurrentValues assumes the order of the parameters passed in, is the same as the order in the report

Resolution

  • Create a Case statement that tests for the parameter
  • The following is a work-around for the issue:

private void ReportDocumentSetParameters(CrystalDecisions.CrystalReports.Engine.ReportDocument rpt)
         {
             foreach (CrystalDecisions.CrystalReports.Engine.ParameterFieldDefinition pField in (ParameterFieldDefinitions) rpt.DataDefinition.ParameterFields)
                 {
                     switch (pField.Name)
         {
             case "@AA":
                 {
                     SetCrystalParam(rpt, "@AA", "100");
                 }
                 break;
             case "@BB":
                 {
                     SetCrystalParam(rpt, "@BB", "2");
                 }

             break;
             case "@CC":
                 {
                     SetCrystalParam(rpt, "@CC", null);
                 }

          break;
         }
         }

Keywords

KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , Bug Filed

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio