I wrote a program that generates PDFs from a Crystal Report, then emails those PDFs to someone. The program works great on my development machine, but when I copy the bin\Release directory to the Windows 2000 Server (machine where I'd like to run it), it starts to run and then generates this error and 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 OCCURS EVERYWHERE EXCEPT WHEN RUNNING FROM VISUAL STUDIO.
.Net 2.0 is installed on that machine, and I've since installed CRRedist2005_x86.msi with no effect. I even get the "Send Error Report to Microsoft" dialog, even though I'm using try/catch to print the exception to a file. Even when the catch block 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;
}
}
Am I not including all the proper references and using statements? I've tried many combinations, but no effect.
This could also be an issue with the fact that the CR assemblies shipped with visual studio are a different version to the full product.
If you are having trouble with the runtimes you download from business objects try the runtime here:
https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=56787567
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With