Question

Locked

How do i send an error e-mail in vb.net?

By brian ·
I have a piece of code written with an insert statement. If the insert statement works, I want to send an e-mail telling certain people the information inserted into the db (which works well). If it fails, I have a try/catch in the code which responds back with an error message on the entering persons screen (which works) and is to send an e-mail to our IT department (which works). Here is the catch...the error e-mail goes out irregaurdless if the insert statement works or not. If the insert goes through, the error message IS NOT displayed on the entering persons screen, yet I still get the error e-mail saying the insert failed, but I also get the e-mail that would be sent if the insert worked. If the insert fails, i get the error written to the screen and the error e-mail only. I have the error e-mail in the try/catch loop to catch the failure, and the "insert worked" email outside of and before the try/catch loop. Any suggestions?

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Should/Could be somethig like this

by Tony Hopkinson In reply to How do i send an error e- ...

But I'd have something like

Try{
DoInsert();
EmailSucess();
}
Catch(Exception (???) ex)
{
EmailFailure();
DisplayError()
}

Or better still IMHO
Success =false;

Try{
DoInsert();
Success =true;
}
Catch(Exception (???) ex)
{
DisplayError(ex)
}
Try
{ DoEmail(Success)
Catch(Exception (???)
{
DisplayError()
}

Don't like the idea of something as complex as email ina catchblock, if it throws and exception, you could be all over the place.

PS if you are using SQL server as your backend, you could do this in your sql you know
SQL Mail and Raiserror with a StoredProc.

Back to Software Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums