Pass Text to SQL Server Job History - SOLVED

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Pass Text to SQL Server Job History - SOLVED

Post by mightycpa » Tue Jan 10, 2017 3:41 pm

Hi,

I have a small macro that tests for certain conditions as part of a larger SQL Server job. It returns one of various exit codes that indicate what things wrong, but I'd like to enhance it so that all conditions are checked before it returns success or failure.

Right now, when I encounter an error, I exit with

Exit>2

And then I check the log, go look up what a 2 means, I fix it, and I run it again to see if anything else fails. What I'd rather do is to print descriptions into the SQL Server job history and then just fail after I check everything.

If I was running a SP, I'd simply include code that says

PRINT ** this is the message that goes in my job history **

How can I do that with MS? I'd rather not connect to db, issue SQL to print, because that involves un/pw issues.

PS: I know all about message boxes, writing to a log, etc. I'm not looking for a workaround. I want to get my message in the SQL Server log. Thanks.
Last edited by mightycpa on Tue Jan 10, 2017 5:38 pm, edited 1 time in total.
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

mightycpa
Automation Wizard
Posts: 343
Joined: Mon Jan 12, 2004 4:07 pm
Location: Vienna, VA

Re: Pass Text to SQL Server Job History

Post by mightycpa » Tue Jan 10, 2017 5:38 pm

Solved! Two steps:

use SOWriteLn
Compile as a Console app

thanks
"A facility for quotation covers the absence of original thought." - Lord Peter Wimsey

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts