Question

  • Creator
    Topic
  • #2210991

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

    Locked

    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?

All Answers

  • Author
    Replies
    • #2843457

      Clarifications

      by brian ·

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

      Clarifications

    • #2843405

      Should/Could be somethig like this

      by tony hopkinson ·

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

      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.

Viewing 1 reply thread