SQL Agent Job succeeds even though step should fail

  • Does anyone know why a Transact-SQL job step that executes a stored procedure and returns a "Query timeout" response continues on as if the job step succeeded?

    Is there anyway to prevent this behavior?

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • The step must have "Go to the next step" as "On failure Action".

    See advanced tab in Job STep properties to set up this option.

  • Brandie Tarvin (1/6/2012)


    Does anyone know why a Transact-SQL job step that executes a stored procedure and returns a "Query timeout" response continues on as if the job step succeeded?

    Is there anyway to prevent this behavior?

    I may be missing the obvious. How do you generate a "Query Timeout" in a stored procedure in a SQL Agent Job?

  • azdzn (1/6/2012)


    The step must have "Go to the next step" as "On failure Action".

    See advanced tab in Job STep properties to set up this option.

    There's no must about it. You misunderstand what I'm saying. I'm not talking about the Advanced Actions.

    The job step itself ends with success. It does not fail. It should fail, but it is not failing.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • MysteryJimbo (1/6/2012)


    Brandie Tarvin (1/6/2012)


    Does anyone know why a Transact-SQL job step that executes a stored procedure and returns a "Query timeout" response continues on as if the job step succeeded?

    Is there anyway to prevent this behavior?

    I may be missing the obvious. How do you generate a "Query Timeout" in a stored procedure in a SQL Agent Job?

    It's not that hard. It's easier, in fact, to get a Query Timeout in a job step than it is in SSMS. In this instance, the proc has a very heavy query load and is doing lots of calcs. This particular proc is also retrieving information across a Linked Server.

    To be clear: I'm not concerned with fixing the timeout issue itself. I've got that covered. What I'm concerned with is how to force a SQL Agent job step to fail if it runs into a timeout issue.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Brandie Tarvin (1/6/2012)


    To be clear: I'm not concerned with fixing the timeout issue itself. I've got that covered. What I'm concerned with is how to force a SQL Agent job step to fail if it runs into a timeout issue.

    I believe you'll have to wrap the call with a TRY/CATCH and do a custom RAISEERROR if it occurs, but I don't have the ability to modify my network to create a mini-lab to confirm I can see the same functionality and that it'll cure it.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • your job is a success because you've successfully executed a script which should fail. lol. kiddin.

    FYI that SQL server checks your script before you could create the job. 😀 it should also fail during job creation.

    you may want to share your script for this. so we could discuss this weird event. 🙂

    ===============================================================

    "lets do amazing" our company motto..

  • Evil Kraig F (1/6/2012)


    Brandie Tarvin (1/6/2012)


    To be clear: I'm not concerned with fixing the timeout issue itself. I've got that covered. What I'm concerned with is how to force a SQL Agent job step to fail if it runs into a timeout issue.

    I believe you'll have to wrap the call with a TRY/CATCH and do a custom RAISEERROR if it occurs, but I don't have the ability to modify my network to create a mini-lab to confirm I can see the same functionality and that it'll cure it.

    Craig, I get what you're saying, but I can't figure out how to pass the error outside of the code context to fail the job step itself. Raising an error is, in and of itself, a successful prosecution of the code. And I see no options within the job step window that allow me to set success or failure of that job step.

    The only option I'm seeing is having that error attempt to update the sysjobsteps table, but I hate the idea of updating sys tables (if I could even do that anymore).

    jnuqui (1/8/2012)


    FYI that SQL server checks your script before you could create the job. 😀 it should also fail during job creation.

    SQL Server only checks for syntax errors and object existence during job creation. There's no reason why job creation would fail in this instance.

    jnuqui (1/8/2012)


    you may want to share your script for this. so we could discuss this weird event. 🙂

    Exec MyServer.MyDB.MySchema.MyProc;

    That's all it is, one simple line of code in a Transact-SQL job step. And I'm not the only person who has this issue. When I googled the problem, I found articles referencing SQL 2005 too with similar comments (the job step succeeded when the query timed out). Unfortunately, none of those articles had a solution to my problem.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Brandie Tarvin (1/9/2012)


    Evil Kraig F (1/6/2012)


    Brandie Tarvin (1/6/2012)


    To be clear: I'm not concerned with fixing the timeout issue itself. I've got that covered. What I'm concerned with is how to force a SQL Agent job step to fail if it runs into a timeout issue.

    I believe you'll have to wrap the call with a TRY/CATCH and do a custom RAISEERROR if it occurs, but I don't have the ability to modify my network to create a mini-lab to confirm I can see the same functionality and that it'll cure it.

    Craig, I get what you're saying, but I can't figure out how to pass the error outside of the code context to fail the job step itself. Raising an error is, in and of itself, a successful prosecution of the code. And I see no options within the job step window that allow me to set success or failure of that job step.

    The only option I'm seeing is having that error attempt to update the sysjobsteps table, but I hate the idea of updating sys tables (if I could even do that anymore).

    Hm, what about something like this:

    TRY

    (Exec MyServer.MyDB.MySchema.MyProc)

    CATCH

    (SELECT IDontExist FROM TableNotThere)

    END


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • Evil Kraig F (1/10/2012)


    Brandie Tarvin (1/9/2012)


    Evil Kraig F (1/6/2012)


    Brandie Tarvin (1/6/2012)


    To be clear: I'm not concerned with fixing the timeout issue itself. I've got that covered. What I'm concerned with is how to force a SQL Agent job step to fail if it runs into a timeout issue.

    I believe you'll have to wrap the call with a TRY/CATCH and do a custom RAISEERROR if it occurs, but I don't have the ability to modify my network to create a mini-lab to confirm I can see the same functionality and that it'll cure it.

    Craig, I get what you're saying, but I can't figure out how to pass the error outside of the code context to fail the job step itself. Raising an error is, in and of itself, a successful prosecution of the code. And I see no options within the job step window that allow me to set success or failure of that job step.

    The only option I'm seeing is having that error attempt to update the sysjobsteps table, but I hate the idea of updating sys tables (if I could even do that anymore).

    Hm, what about something like this:

    TRY

    (Exec MyServer.MyDB.MySchema.MyProc)

    CATCH

    (SELECT IDontExist FROM TableNotThere)

    END

    That's what I used to do when I did more dev work. I did SELECT * FROM BreakFromSP... Worked like a charm!

    Jared
    CE - Microsoft

  • I'll give the suggestion a try and see what happens. Thanks,

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Brain fart today... Erasing irrelevant comment...

    Jared
    CE - Microsoft

  • Brandie, do you have any extra information on what type of timeout it is? Is it a lock timeout, a remote query lockout, a network timeout, a login timeout?

    I'm trying to recreate the issue in my sandboxes today out of curiousity and it would help if I knew which exact one to muck with the sandboxes.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • To add to that, it depends on the timeout. For example, a lock timeout:

    Definately will fail the step (and thus the job).

    I did this by trying to update the same record via a proc called from the job step as I had in a hanging transaction in another query window.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA

  • Evil Kraig F (1/11/2012)


    Brandie, do you have any extra information on what type of timeout it is? Is it a lock timeout, a remote query lockout, a network timeout, a login timeout?

    I think it's a remote query timeout.

    It ran over the weekend and I didn't notice the problem until two days later because the job didn't fail:

    OLE DB provider "SQLNCLI10" for linked server "MyServer" returned message "Query timeout expired". [SQLSTATE 01000] Job 'XXXX Report Run' : Step 2, 'Run XXX Proc' : Began Executing 2012-01-02 04:40:02

    EDIT: I've been fighting other fires, so haven't had a chance to test a deliberate failure of a job. As soon as I put these out, I'm going to go back to testing the job itself.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

Viewing 15 posts - 1 through 15 (of 36 total)

You must be logged in to reply to this topic. Login to reply