VS.Net 8 & Crystal Report question

G

Guest

Hi
I am working on a C# Windows Application that builds an invoice (CR)
converts to PDF and attach to email one at a time.

This works untill my invoice count get over 40 to 50 invoices then I start
getting errors. The errors vairy. sometimes IO sometime "unable to load
report".

Has anyone here had a need to creat reports in mass?

Code:Example
// before the Form InitializeComponent
ReportDocument r = new ReportDocument();
//
// Get Invoice Emailing Data
DataSet ds = DataCalls.getInvoiceEmailList(val1, val2);
int rowcount = 0;
foreach (DataRow dr in dt.Rows)
{
BuildInvoiceReport(ds.Tables[0].Rows[rowcount][0].ToString(),
ds.Tables[0].Rows[rowcount][1].ToString()ds.Tables[0].Rows[rowcount][2].ToString()ds.Tables[0].Rows[rowcount][3].ToString());
EmailPDF();
}
//Get invoice data and build Report one at a time
private void BuildInvoiceReport(int CommodityID, int InvoiceNumber, string
OrderBy)
{
DataSet ds = DataCalls.getInvoiceDataSet(CommodityID, InvoiceNumber,
InvoiceNumber, OrderBy, 0);
r = null;
r = new Invoice();
r.SetDataSource(ds);
r.SetParameterValue(0, OrderBy);
r.SetParameterValue(1, comboBox.SelectedValue.ToString());
}
// email invoice
private void EmailPDF(int InvoiceNumber)
{
string ExportPath;
string emailFrom;
string subject;
string fName;
ExportPath = Application.StartupPath.ToString();
fName = ExportPath + "\\Invoice" + InvoiceNumber + ".pdf";
r.ExportToDisk(ExportFormatType.PortableDocFormat, fName);
emailFrom = "(e-mail address removed)";
subject = "Invoice#: " + InvoiceNumber + ".pdf";
emailTo = "(e-mail address removed)";

SmtpClient smtpclient = new SmtpClient();
MailMessage mailmsg = new MailMessage();
smtpclient.Host = ConfigurationManager.AppSettings["MailServer"];
MailAddress fromaddress = new MailAddress(emailFrom);
mailmsg.From = fromaddress;
mailmsg.To.Add(emailTo);
mailmsg.Subject = subject;
mailmsg.Body = body;
mailmsg.Attachments.Add(new Attachment(attachmentFilePath));
smtpclient.Send(mailmsg);
//Dispose attachment object so that file can get deleted
mailmsg.Attachments.Dispose();
File.Delete(attachmentFilePath);
}

Thanks for any help

Brian
 
B

Bruce Wood

BrianDH said:
Hi
I am working on a C# Windows Application that builds an invoice (CR)
converts to PDF and attach to email one at a time.

This works untill my invoice count get over 40 to 50 invoices then I start
getting errors. The errors vairy. sometimes IO sometime "unable to load
report".

Has anyone here had a need to creat reports in mass?

I didn't study your code too closely, but from what I saw it looks
fine. We are using CR to produce mass reports here, too, using the same
"push" model that you appear to be using. I've produced reports
containing upwards to 180 pages of purchase orders with no problems at
all.

Crystal can be flakey, but in my experience it's usually me
misinterpreting the (terrible) MSDN documentation for CR more than
anything else.

Exactly where does the error occur, when it occurs?
 
G

Guest

Hi

The reports themselves are never more than a few pages. Its just we create
one after the other and email and delete as we go. Sometimes there will be
over 200 different invoices (CR) created and Emailed.

I get errors sometimes at the:
r.SetDataSource(ds);
also at the: mailmsg.Attachments.Add(new Attachment(attachmentFilePath));

CR flakey is an understatment.

Thanks
B
 
B

Bruce Wood

BrianDH said:
Hi

The reports themselves are never more than a few pages. Its just we create
one after the other and email and delete as we go. Sometimes there will be
over 200 different invoices (CR) created and Emailed.

I get errors sometimes at the:
r.SetDataSource(ds);
also at the: mailmsg.Attachments.Add(new Attachment(attachmentFilePath));

Can you post the exact text of the errors (including the stack dump)
and indicate where in your code each of them occurs? One sounds like an
SMTP error, while the other sounds like Crystal getting pissy about
something.

By the way, how did you design your reports? Did you export your
DataSet to an XSD and use that as the basis for your report design? If
so, is your .rpt up to date with the latest XSD? One problem I've come
across frequently is that the data in the DataSet doesn't exactly match
the schema I used to produce the report template. If that happens, then
the reporting dies "sometimes" whenever the data for a particular
report doesn't match the schema, but works other times whenever the
offending data items are absent.

If you haven't already, try using .WriteXmlSchema on the DataSet to get
an XSD out and then use Crystal's "Verify Database" command to update
the .rpt to the exported schema.
CR flakey is an understatment.

Oh, it's not that bad. It's no worse than Win32 programming used to be:
bad documentation, learning by experimentation and folklore, things
fall over occasionally. That sort of thing.
 
G

Guest

Hi Bruce

OK, the SMTP error is 'caused by bad formating in email address. I have
fixed that with addtional validation on the client.

The CR was due to the fact they they were depending on "r = null" to clear
memory when there was also needed " r.close()" first. I found about 3 gig's
of temp.rpt files in the temp dir on the accounting box.

Anyway, the problem seems to be fixed.

Thanks for the help, I was stressing.

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top