Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 1234»»»

SQL Agent Job succeeds even though step should fail Expand / Collapse
Author
Message
Posted Friday, January 6, 2012 6:45 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Monday, August 25, 2014 7:14 AM
Points: 7,197, Visits: 6,341
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 Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1231429
Posted Friday, January 6, 2012 9:42 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Tuesday, July 15, 2014 1:52 PM
Points: 1,511, Visits: 254
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.



Post #1231571
Posted Friday, January 6, 2012 9:57 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, August 18, 2014 3:04 AM
Points: 1,362, Visits: 15,269
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?
Post #1231581
Posted Friday, January 6, 2012 11:20 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Monday, August 25, 2014 7:14 AM
Points: 7,197, Visits: 6,341
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 Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1231628
Posted Friday, January 6, 2012 11:24 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Monday, August 25, 2014 7:14 AM
Points: 7,197, Visits: 6,341
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 Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1231630
Posted Friday, January 6, 2012 12:44 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 7:18 PM
Points: 6,250, Visits: 7,409
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 | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1231688
Posted Sunday, January 8, 2012 11:27 PM


SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, May 13, 2014 1:51 AM
Points: 49, Visits: 205
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. :D 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..
Post #1232211
Posted Monday, January 9, 2012 5:26 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Monday, August 25, 2014 7:14 AM
Points: 7,197, Visits: 6,341
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. :D 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 Administrator

Webpage: http://www.BrandieTarvin.net
LiveJournal Blog: http://brandietarvin.livejournal.com/
On LinkedIn!, Google+, and Twitter.

Freelance Writer: Shadowrun
Latchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.
Post #1232333
Posted Tuesday, January 10, 2012 2:29 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 7:18 PM
Points: 6,250, Visits: 7,409
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 | Forum Netiquette
For index/tuning help, follow these directions. |Tally Tables

Twitter: @AnyWayDBA
Post #1233538
Posted Tuesday, January 10, 2012 2:42 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 1:34 PM
Points: 2,693, Visits: 3,384
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!


Thanks,

Jared
SQL Know-It-All

How to post data/code on a forum to get the best help - Jeff Moden
Post #1233558
« Prev Topic | Next Topic »

Add to briefcase 1234»»»

Permissions Expand / Collapse