Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm new to crystal report. I'm facing an issue that my report show no data although the dataset showed it did have data during debugging. I noticed that everything went wrong after the line " m_rptViewReport.SetDataSource(ds); ", it show "HasRecords = Function evaluation disabled because a previous function evaluation timed out. You must continue execution to reenable function evaluation crystal reports" Basically, I'm trying to export the data to xls file using push method. I'm using VS2015 and my crystal report assembly version is 13.0.3500.0

Pls take a look at my code
C#
public bool ExportToFile(DataSet ds,string fileType)
    {
        try
        {
            object obj = null;
            char[] split ={ '.' };
            CrystalDecisions.CrystalReports.Engine.ReportDocument m_rptViewReport = null;


                if (File.Exists(Request.PhysicalApplicationPath + "\\" + this.ReportFile))
                {
                   try {
                    m_rptViewReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                    m_rptViewReport.Load(Request.PhysicalApplicationPath + "\\" + this.ReportFile);

                       ds.WriteXml("D:\\testfile.XML", XmlWriteMode.WriteSchema); //the output XML file does have data
                       m_rptViewReport.SetDataSource(ds);//something went wrong after this line
                   }
                   catch (Exception ex) //nothing happened here
                   {
                       throw ex;
                   }
                }
                else
                    this.SetTextTitle(Resources.GetLanguage("msgNoFile") + " " + this.ReportFile);

            if (m_rptViewReport.HasRecords){ //I added this line later and founded that the value is not TRUE
            if (m_rptViewReport != null)
            {
               SetReportParameterValue(m_rptViewReport);

                       Response.ContentType = "application/vnd.ms-excel";

                       try {
                           m_rptViewReport.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.Excel, Response, true, this.ReportCode);

                       }
                       catch (System.Threading.ThreadAbortException ex1)
                       {
                           //throw ex1;
                       }

            }
           }
           return true;
        }
        catch(Exception ex)
        {
           return false;
        }
    }

Thanks

What I have tried:

- I added useLegacyV2RuntimeActivationPolicy="true" to app.config and then removed it but both did not work.
- I also removed all CrystalReportViewer from my UI.
Posted
Updated 12-Sep-17 20:24pm
Comments
Graeme_Grant 12-Sep-17 23:54pm    
Have you set breakpoints to check that in fact data is being passed to CR?

1 solution

Best Approach from my exprerience,

Create a new aspx page, modified everythings inside Page_init() (because not working other stage), make sure also put CrystalReportViewer on markup views.

protected void Page_Init(object sender, EventArgs e)
        {
            rptfile = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            rptfile.Load(Server.MapPath("~/Reports/Report.rpt"));
            rptfile.SetDatabaseLogon("sa", "123", @"192.168.102.1\Database", "Data");
            rptfile.Refresh();

            .....

            OleDbDataAdapter sql = new OleDbDataAdapter(query, Connection);
                //OleDbDataAdapter sql = new OleDbDataAdapter();
                //sql.SelectCommand = new OleDbCommand(query, Connection);
            DataSet ds = new DataSet();
            sql.Fill(ds);

            rptfile.SetDataSource(ds.Tables[0]);
            this.CrystalReportViewer1.ReportSource = rptfile;
            CrystalDecisions.Shared.ConnectionInfo connectinfo = new 
            CrystalDecisions.Shared.ConnectionInfo();
            connectinfo.ServerName = @"192.168.102.1/Database";
            connectinfo.UserID = "sa";
            connectinfo.Password = "123";
            connectinfo.DatabaseName = "Data";

            CrystalDecisions.Shared.TableLogOnInfos TableLoginInfos = 
            this.CrystalReportViewer1.LogOnInfo;

            foreach (CrystalDecisions.Shared.TableLogOnInfo TableLogon in 
             TableLoginInfos)
            {
                    TableLogon.ConnectionInfo = connectinfo;
            }

            rptfile.SetParameterValue(@"param1", Class1.param1);
            rptfile.SetParameterValue(@"param2", Class2.param2);

            this.CrystalReportViewer1.HasToggleGroupTreeButton = false;
            this.CrystalReportViewer1.HasToggleParameterPanelButton = false;
            this.CrystalReportViewer1.ToolPanelView = ToolPanelViewType.None;
        }


Inside your web.config (to help web server find the path in easy),

<configuration>
  <configSections>
    <sectionGroup name="businessObjects">
      <sectionGroup name="crystalReports">
        <section name="rptBuildProvider" type="CrystalDecisions.Shared.RptBuildProviderHandler, CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, Custom=null" />
        <section name="crystalReportViewer" type="System.Configuration.NameValueSectionHandler" />
      </sectionGroup>
    </sectionGroup>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <businessObjects>
    <crystalReports>
      <rptBuildProvider>
        <add embedRptInResource="true" />
      </rptBuildProvider>
      <crystalReportViewer>
        <add key="ResourceUri" value="/crystalreportviewers13" />
      </crystalReportViewer>
    </crystalReports>
  </businessObjects>
</configuration>
 
Share this answer
 
Comments
Member 13406906 13-Sep-17 4:48am    
Thanks for your reply.
Basically I just want to export the report to xls file and I have nothing to do with CrystalReportViewer.
During Debugging, I could see the DataSet did have data but something went wrong with the method SetDataSource..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900