1
votes

When I call ExportToDisk(). In some machine do well. But in some machine throw the exception.

Exceptoion

This field name is not known. Error in File C:\Windows\TEMP\RPTH010_Report01 {C0D0E863-1741-4917-A455-B23347EA4FD6}.rpt: Error in formula <填單日期>. 'numberVar RocDateNumber := {RPTH010_Report01.D01_APLDATE};' This field name is not known.
This field name is not known. Error in File C:\Windows\TEMP\RPTH010_Report01 {C0D0E863-1741-4917-A455-B23347EA4FD6}.rpt: Error in formula <填單日期>. 'numberVar RocDateNumber := {RPTH010_Report01.D01_APLDATE};' This field name is not known.

stack trace

CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext) CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext) CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToDisk(ExportFormatType formatType, String fileName) JcsWebSolution.Report.CRDocument.SaveToDisk() mOffice.Models.Report.ASSET.RPTH010_Report01.PrintReport() mOffice.Models.Report.ReportBase.PrintProcess()

My system

  • CrystalDecisions.CrystalReports.Engine.dll, v10.5.3700.0
  • CrystalDecisions.Shared.dll, v10.5.3700.0
  • Window Server 2012 R2
  • Visual Studio 2013

I try to fixed the bug by

  • Reinstall crystal report runtime SP12.
  • Checking the font is in system.

And I try to print a report without formula and it can export well. And I add the concat string formula it just broken.

My code

public class result
{
  public string { get; set;}
}

public bool DoExport()
{
  List<result> test = new List<result>();
  test.Add(new result { test = "123" });

  DataTable input = ListToDataTable(test);

  input.TableName = "test";
  m_RptDataSet.Tables.Add(input);

  ReportDocument m_ReportDocument = new ReportDocument();

  m_ReportDocument.Load(HttpContext.Current.Server.MapPath("~/RPT/test.rpt"));
  m_ReportDocument.SetDataSource(input);
  m_ReportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, "test.pdf");

  m_ReportDocument.Close();
  m_ReportDocument.Dispose();

  m_ReportDocument = null;
}

public  DataTable ListToDataTable<T>(List<T> list)        
{
  PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));

  DataTable dt = new DataTable();

  object[] values;

  for (int i = 0; i < props.Count; i++)            
  {            
    PropertyDescriptor prop = props[i];
    dt.Columns.Add(prop.Name, prop.PropertyType);            
  }

  foreach (T item in list)
  {
    values = new object[props.Count];
    for (int i = 0; i < values.Length; i++)
    {
      values[i] = props[i].GetValue(item);
    }

    dt.Rows.Add(values);
  }

  return dt;
}

concat string formula

{RPTH040_Test.test} + " test Function"

But in other machine just fine. Does anyone has the same problem?

Updated

I test a new report which have 3 records without formula. I find that the report can export, but does not show records. So I guess the main reason is that SetDataSource() doesn't work in my machine(windows 2012 R2). I try to add the code to Web.config.

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>

It still not work. Does anyone know about this?

2
have you checked your table structure? its not getting the required field used in formulaSiva
What's the field's data type? Is it ever null?craig
To @craig , Its type is string.Milkker
I test a new report which have 3 records without formula. I find that the report can export, but does not show the records. So I guess the main reason is SetDataSource() doesn't work in the machine(windows 2012 R2). I try to add <startup useLegacyV2RuntimeActivationPolicy="true"><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup> to Web.config. It still not work. Does anyone know about this?Milkker

2 Answers

1
votes

I got the same error in Crystal Report after making series of changes in the respective stored procedure, finally I found that I was using a field in my formulas which were removed from my sp (earlier this field was there when I have created the formula and then removed from the SP), so I updated my formula with proper updated field now and then its gone.

Hope it will help someone.

0
votes

I got the main result from SCN.

CR 10.5 (CR for VS 2008) is not compatible / tested supported with Win 2012. It is also not compatible with VS 2013. Upgrade CR to CR for VS 2013 (13.0).

Bhushan

More detail -> Windows server 2012 R2 SetDataSource doesn't work | SCN