Click here to Skip to main content
15,889,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have to print a report offline, where the result of the report doesn't exists into the DB.
I added the reference to CrystalDecisions.CrystalReports.Engine v2.0.50727 (version 12.0.2000.0) on my .Net Framework 4 project.
I runned the method that have to print the report, and save the dataset into an XML file:
C#
internal void PrintData(string reportFile, string printerName)
{
    DataTable DT = CreateDataTable();

    if (DT.Rows.Count > 0)
    {
        DataSet DS = new DataSet();
        DS.DataSetName = "ReportDataset";
        DS.Namespace = "ReportNamespace";
        DS.Tables.Add(DT);

        DS.WriteXml(Environment.GetEnvironmentVariable("TEMP") + "\\ReportDataset.xml", XmlWriteMode.WriteSchema);

        if (false)
        {
            ReportDocument report = new ReportDocument();
            report.Load(reportFile);
            report.SetDataSource(DS);
            PrintDialog pd = new PrintDialog();
            pd.PrinterSettings.PrinterName = printerName;
            if (pd.ShowDialog() == DialogResult.OK)
            {
                report.PrintOptions.PrinterName = pd.PrinterSettings.PrinterName;
                report.PrintToPrinter(1, false, 0, 0);
            }
        }
    }
}

Then I create the Report with Crystal Reports 2008 (v12.0.0.683). I create the connection as a XML connection, to the XML file I created.
It seems to run.
I changed the if (false) into if (true) to see the result.
The statement
C#
report.SetDataSource(DS);
throw an unhandled exception of type DataSourceException (Unknown error on database connector).

What I have tried:

I tried also to perform the print in Pull mode, and it runs well, but it's unelegant to write the xml file because Crystal Reports don't performs the SetDataSource method. There is something wrong in versions?
Posted
Comments
njammy 5-Sep-16 10:16am    
Why have you placed a if(false) statement?
Menci Lucio 5-Sep-16 10:19am    
@kjammy Because I had not a report file. I put if(false), created the XML, created the Report, replaced the if(false) with if(true)
njammy 5-Sep-16 10:33am    
But you are not evaluating boolean to anything. It is better to just get rid of the if(true/false)

I'm afraid I don't have v12.0.0.683 to test if I can recreate the issue, but I used 13.0.2000.0 with VS2015 and works fine. Try that version.
Menci Lucio 5-Oct-16 8:40am    
How did you install it? Where I can find it? I wasn't able...
I installed the CRRuntime_12_3 a lot of time ago, and I found the CristalDecision.CrystalReports.Engine.dll in C:\Program Files (x86)\Business Objects\Common\4.0\managed.
Now I just installed the CRforVS_redist_install_64bit_13_0_17 (downloaded from http://scn.sap.com/docs/DOC-7824), disinstalled ed installed the CRRuntime_64bit_13_0_12 from http://downloads.i-theses.com/index.php?option=com_downloads&Itemid=481&task=downloads&groupid=9&id=101), but in booth situations I wasn't able to find the CristalDecision.CrystalReports.Engine.dll in my disk but the v12.0 I already had.

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