Send error messages in DatabaseMail when SQL Job fails/succeeds

Hi ,
I have setup a profile and account for sending mail using DatabaseMail. I have a SQL JOB. If the job fails, I receive an Email.
Till this point, everything works fine. This is what the email looks like :
JOB RUN: 'GenerateJVForLabourAndOverheads_R11Testing' was run on 20-12-2012 at 10:10:50
DURATION: 0 hours, 0 minutes, 0 seconds
STATUS: Failed
MESSAGES: The job failed. The Job was invoked by Schedule 58 (Execute SP). The last step to run was step 1 (Execute SP).
Now what I want is, if the job fails for any reason, that error message should appear in the email message body.
for example, FK_Constraint error , Conversion errors or any error that caused my sql job to fail.
Is this possible ?
Any help appreciated,
Thanks,
Lok..

 This is one way to do, assuming your job has 2 steps and step 1 does the main part.
So,in your step 2 of the job, you can add the below code and 
declare @body1 varchar(8000) 
select top 1 @body1 = [Message] from msdb.dbo.sysjobhistory A INNER JOIN msdb.dbo.sysjobs B ON B.Job_id = A.Job_id
 where B.Name = <<JobNaMe>> and A.step_id =1 order by instance_id desc
 EXECUTE msdb.dbo.sp_send_dbmail @profile_name = <<YourMail profile>>
,@recipients = <<RecipeintEmail>>,@subject =<<Your subject>>,@body = @body1
 I guess, you can also  log the job step output to an outputfile and have it sent as an attachment to your mail... this might help if you have many steps in one job....
HTH!!
Please mark as 'Answer', if the solution solves your problem.

Similar Messages

  • HT4863 I have an error message coming up when trying to send an email which says 'sending the message failed because you're exceeding the limit' can anyone help me to resolve this please

    I have an error message coming up when trying to send an email which says 'sending the message failed because you're exceeding the limit' can anyone help me to resolve this please

    Try reentering the password in your iCloud mail settings.

  • When i do initial set up w creative cloud set uo wont run send error message"installer failed to initialize" why and how can i get pass this

    When I do initial set up with creative cloud set up it wont run a send error message "installer failed to initialize" comes up. Why and how can I get passed this?

    Error "Installer Failed to Initialize" | Install desktop application | Windows

  • Best Practices Question: How to send error message to SSHR web page.

    Best Practices Question: How to send error message to SSHR web page from custom PL\SQL procedure called by SSHR workflow.
    For the Manager Self-Service application we’ve copied various workflows which were modified to meet business needs. Part of this exercise was creating custom PL\SQL Package Procedures that would gather details on the WF using them on custom notification sent by the WF.
    What I’m looking for is if/when the PL\SQL procedure errors, how does one send an failure message back and display it on the SS Page?
    Writing information into a log or table at the database level works for trouble-shooting, but we’re looking for something that will provide the end-user with an intelligent message that the workflow has failed.
    Thanks ahead of time for your responses.
    Rich

    We have implemented the same kind of requirement long back.
    We have defined our PL/SQL procedures with two OUT parameters
    1) Result Type (S:Success, E:Error)
    2) Result Message
    In the PL/SQL procedure we always use below construct when we want to raise any message
    hr_utility.set_message(APPL_NO, 'FND_MESSAGE_NAME');
    hr_utility.raise_error;
    In Exception block we write below( in successful case we just set the p_result_flag := 'S';)
    EXCEPTION
    WHEN APP_EXCEPTION.APPLICATION_EXCEPTION THEN
    p_result_flag := 'E';
    p_result_message := hr_utility.get_message;
    WHEN OTHERS THEN
    p_result_flag := 'E';
    p_result_message := hr_utility.get_message;
    fnd_message.set_name('PER','FFU10_GENERAL_ORACLE_ERROR');
    fnd_message.set_token('2',substr(sqlerrm,1,200));
    fnd_msg_pub.add;
    p_result_message := fnd_msg_pub.get_detail;
    After executing the PL/SQL in java
    We have written some thing similar to
    orclStmt.execute();
    OAExceptionUtils.checkErrors (txn);
    String resultFlag = orclStmt.getString(provide the resultflag bind no);
    if ("E".equalsIgnoreCase(resultFlag)){
    String resultMessage = orclStmt.getString(provide the resultMessage bind no);
    orclStmt.close();
    throw new OAException(resultMessage, OAException.ERROR);
    It safely shows the message to the user with all the data in the page.
    We have been using this construct for a long time for all our projects. They are all working as expected.
    Regards,
    Peddi.

  • Sending error messages

    When I send error messages it disables the back, exit and cancel button.
    How can I enable them?

    Use popup window to notify errors...
    CALL SCREEN '1100' AS WINDOW STARTING AT 10 10.
    <i>OR</i>
    CALL FUNCTION 'POPUP_TO_CONFIRM'
      EXPORTING
       TITLEBAR                    = 'Test '
        text_question               = 'Error message'
       DISPLAY_CANCEL_BUTTON       = ' '
    Regards
    ramana

  • Error message from web - when opening pdf files

    Hi,
    I receive the following error message a lot when I try to open an educational pdf file from the web.  What do I need to do to 1. see, 2. print and 3. save these type of educational pdf files from the web?  I am using a MacBookPro OS X.
    Thanks for your help and sorry I could not find an answer on the forum. 
    Example:  I try to import or download MIT18_06SCF11_Ses3.5sum 2.pdf onto my desktop - which seems successful.  However when I try to open this file, I get the following error message.:
    "Adobe Reader could not open 'MIT18_06SCF11_Ses3.5sum 2.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)."

    Yes i tried following your list of commands and got the same error from MyMathLab by Pearson Publishing or the other link.  I'm beginning to wonder if they are protected. 
    As you probably guess - I am not computer savvy.  I will take my laptop to school tomorrow and ask another student. 
    Thanks for your followup.

  • Error message MRM_DRSEG_FILL(SAP_DRSEG_FILL) when FI Vendor posting (IDOC)

    Hello Gurus,
    We used INVOIC IDOC type to do FI Vendor posting for intercompany flow (between 2 plants / 2 differents companies).
    We get the error message "MRM_DRSEG_FILL(SAP_DRSEG_FILL)" when SAP tries to integrate IDOC on Vendor side (to create the Vendor invoice / MIRO).
    There is no VAT between the 2 plants.
    Do you have any idea from where the issue is coming from?
    Many thanks.
    Stéphane

    I found one part of the solution.
    We are working with AFS SAP. So in this case, we should use /AFS/INVOIC02.
    Now it is fine except I get the error message: "Enter a tax code in item 0001".
    I add manualy the "E1EDK04 VAT" segment with the correct VAT.
    The IDOC is posted correctly.
    Do you have any idea to fix it without manual change?
    Many thanks.

  • HT1491 Why do i keep getting the message 'Cannot connect to iTunes Store' when I have done every connection I can find? What does the error message (-1202) mean when I am on the iTunes site on my computer?

    Why do i keep getting the message 'Cannot connect to iTunes Store' when I have done every connection I can find? What does the error message (-1202) mean when I am on the iTunes site on my computer?

    Hi Velvalee,
    While there may not be specific information about that error, here is an article of steps for troubleshooting connectivity issues with the iTunes store:
    Can't connect to the iTunes Store
    http://support.apple.com/kb/ts1368
    If that article does not help, there is a link near the bottom for an additional article of advanced troubleshooting.
    Cheers!
    - Ari

  • I created a book and tried to place order but failed.  I followed the procedures, when the book completed uploading, the message "An error occured uploading your order" pop up.  There was no error message all along when I created the book.

    I created a book and tried to place order but failed.  I followed the procedures, when the book completed uploading, the message "An error occured uploading  your order" appeard.  There was no error message all along when I created the book. I tried several time but failed.

    preview the order and try again - http://support.apple.com/kb/HT1040
    If it still does not work boot into Safe Mode, preview again and try
    With the number of reports in the last few days it may be server overload - if so trying during a time of lower activity might help
    LN

  • An error message came up when updating camera raw 6.7 on my CS5 on windows 8

    I Have Lightroom 5.5 and CS5 Photoshop.
    An error message came up when I tried to update CS5 and Camera raw.
    Can you assist.
    [email protected]
    Regards
    Peter

    Try manual update.
    Product updates

  • I'm trying to sync my phone to my computer and keep getting error message "1140" just when it's about to finish.  My updates are current.  Thoughts?

    I'm trying to sync my phone to my computer and keep getting error message "1140" just when it's about to finish.  My updates are current.  Thoughts?

    Hi hannijin,
    What version of the Mac OS X do you have on your computer?  The version of iTunes that you can install is dependent on the operating system that you have.  For example, the current version of iTunes requires OS X version 10.7.5 or later.
    Finding the OS X version and build information on your Mac - Apple Support
    https://support.apple.com/en-us/HT201260
    Apple - OS X Yosemite - How to Upgrade
    https://www.apple.com/osx/how-to-upgrade/
    Hope that helps ...
    - Judy

  • Error message about forms when ID exported PDF is opened in Reader

    I'm using ID CS2.
    Has anyone successfully made navigation buttons on an exported PDF that doesn't produce an error message about forms when opened in Adobe Reader?
    There's an Adobe page about this that says it's caused by having a stroke too near a link field, but I can't seem to avoid the message if I place more than one button anywhere on a page. I've spent a lot of time playing with this and can't seem to find a workaround.
    Am I a sucker? Is anyone else trying to use this function other than me? It seemed like the perfect solution to this project I produced and now whenever a user opens the PDF they are greeted with a confusing message that has absolutely nothing to do with the functionality of the document.

    Well, everything in those PDFs were form fields. You can make form fields in Acrobat - and then you can right-click on 'em and change their appearance, whether or not they'll accept rich text input, whether or not they'll scroll, and so on. It could also be done in LiveCycle Designer, for what it's worth. I wrote a now-obsolete post about this in response to yours before Mike showed up with this video.
    Probably most of your work on your designs in InDesign would need to be trashed; you'd need to rebuild the whole thing in Acrobat or LiveCycle. I have to say that, unless your targeted documents are extremely simple, that this is one of the worst document translation workflows I've ever seen in the last fifteen years. It might work - I'm trying to keep an open mind, here - but if you have any non-Latin-script languages in your target list, or if print reproduction is what you're after, or if you're expecting tracking revisions to the translations to be anything but a nightmare, I would suggest that you test this method inside and out before progressing any further.

  • Error Message - ORA-06502: PL/SQL: numeric or value error: Bulk Bind: Trunc

    This is driving me nuts!
    I am getting this error from OWB during a mapping process.
    I have checked the input data and it looks fine.
    The run time audit browser just lists all of the steps but does not make it clear which one failed. Is it the last one which is shown (does not have HIDE as selection link.)
    I also tried to determine which row was causing the problem and followed the instructions at http://www.nicholasgoodman.com/bt/blog/2005/07/, but no row_id was recorded in the views. In actual fact there wasn't very much audit info other than that the mapping ran and was complete (even though it failed).
    In the error message section it has, in order
    Map Step - blank
    Rowkey - 35204435256
    Severity - X
    Error Message - ORA-06502: PL/SQL: numeric or value error: Bulk Bind: Truncated Bind
    Object Name - N/A
    Object Column - *
    From the PL/SQL error I thought it may be trying to insert into a data field that was too small, but all of the columns that are used are full of data of length shorter than all of the target tables.
    I have even started running the cursors in the generated PLSQL but I don't get the error by doing this.
    Thanks in advance for any tips at all.

    Thanks for the response.
    I managed to work it out and it had to do with the selection criteria of one of the filters.
    For anyone else facing this error, check to see if any of the rows being inserted has the same key/identifier as some existing in the target table. If so add an extra condition to the where clause.
    This worked for me.

  • How to send error message to forms from Database Trigger

    Hi, Please help me to send error message to forms from Database Trigger?
    RgDs,
    Madesh.R.M

    You are correct, the On-Error trigger is a Forms trigger. However, if your Form is going to display the error generated by the database stored procedure or trigger - you might not see the database error in your Form unless you check the DBMS_ERROR_CODE in the On-Error trigger and manually display the Error Code and associated Text. I've see this happen with a co-worker. The Form she was working on was based on a table with an Before-Insert trigger. Because she was not explicitely handling the error from the Before-Insert trigger in the Forms On-Error trigger, her Form appeared to halt for no reason at all. Once she added code to the On-Error trigger in the Form to handle the DBMS_ERROR_CODE, she discovered the trigger was producing an error and was able to show the error to the user in the On-Error trigger.
    I understand the desire to keep as much as possbile in the database, but with that comes some extra coding in your Forms to handle this. This extra coding could easily be placed in a Forms Library, attached to a Form and called in the On-Error trigger. Your code could look like this:
    DECLARE
       /*This example assumes you have an Alert defined
          in your Form called: 'ERROR' */  
       al_id    ALERT;
       al_text  VARCHAR2(200);  /* Max text of a Forms Alert message*/
       al_btn   NUMBER;
    BEGIN
    IF DBMS_ERROR_CODE != 0 THEN
       /* Error code is ORA-00000 Normal Successful completion
           So only handle non-zero errors  */
       al_text := DBMS_ERROR_CODE||':'||DBMS_ERROR_TEXT;
       al_id := Find_Alert('ERROR');
       set_alert_property(al_id, alert_message_text, al_text);
       al_btn := show_alert(al_id);
    END IF;
    END;Your original question was "How to send error message to forms from Database Trigger?" The answer is you don't because Forms already gets the database error code and database message through the Forms DBMS_ERROR_CODE and DBMS_ERROR_TEXT functions. Look these up in the Forms help and it should clear things up for you.
    Craig...
    Edited by: CraigB on Jun 14, 2010 4:49 PM
    Edited by: CraigB on Jun 14, 2010 4:49 PM
    Edited by: CraigB on Jun 14, 2010 4:50 PM
    Edited by: CraigB on Jun 14, 2010 4:51 PM
    Edited by: CraigB on Jun 14, 2010 4:51 PM

  • TS3274 Error message 5000 received when trying to update ipad software

    How do I resolve this error message 5000 received when trying to update ipad software from my computer?

    iOS: Resolving update and restore alert messages
    http://support.apple.com/kb/TS1275
    iPad: Unable to update or restore
    http://support.apple.com/kb/ht4097
     Cheers, Tom

Maybe you are looking for