I wrote a program that generates PDF files from Crystal Report, and then sends these PDF files to someone. The program works fine on my development machine, but when I copy the bin \ Release directory to Windows 2000 Server (the machine on which I want to run it), it starts and then generates this error and a stack trace:
The type initializer for 'CrystalDecisions.CrystalReports.Engine.ReportDocument' threw an exception. at CrystalDecisions.CrystalReports.Engine.ReportDocument..ctor() at DailyJobCostSummaryEmail.Program.crptToPDF(String reportFile, String jobNum, String outputLocation) in M:\Projects\DailyJobCostSummaryEmail\DailyJobCostSummaryEmail\Program.cs:line 79 at DailyJobCostSummaryEmail.Program.Main(String[] args) in M:\Projects\DailyJobCostSummaryEmail\DailyJobCostSummaryEmail\Program.cs:line 46
ERROR VIEW ANYWHERE, EXCEPT WHEN CONTINUING FROM A VISUAL STUDIO.
.Net 2.0 is installed on this computer, and since then I installed CRRedist2005_x86.msi without effect. I even got the "Send error message to Microsoft" dialog box, although I use try / catch to print the exception to the file. Even when the catch block is executed, my program will not close properly.
static void Main(string[] args) { try { String dir = @"JobCostReports"; DataTable jobs = new DataTable(); using (SqlConnection conn = new SqlConnection(connString)) { String sql = "JC_GetJobsClosedYesterday"; SqlDataAdapter da = new SqlDataAdapter(sql, conn); da.Fill(jobs); } List<String> files = new List<String>(); foreach (DataRow row in jobs.Rows) { files.Add(crptToPDF(@"JobCost.rpt", row["JobNumber"].ToString().TrimEnd(), dir)); } Utilities.sendEmail("[toEmail]", "[FromEmail]", "Job Cost Summaries for Yesterday", "Attached are Job cost summaries for the " + files.Count + " jobs closed yesterday.", files.ToArray()); Console.WriteLine("Email sent."); } catch (Exception e) { using (StreamWriter writer = new StreamWriter("errors.log", true)) { writer.AutoFlush = true; Console.WriteLine(); writer.WriteLine(e.Message); writer.WriteLine(e.StackTrace); } Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); Console.Read(); } finally { } } public static String crptToPDF(String reportFile, String jobNum, String outputLocation) { using (ReportDocument rpt = new ReportDocument()) { rpt.Load(reportFile); rpt.SetParameterValue("@vJobNumber", jobNum); String output = outputLocation + @"\" + jobNum + "_JobCostSummary.pdf"; rpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, output); return output; } }
I do not include all the correct references and use of statements? I tried many combinations, but no effect.
MAW74656
source share