Friday, June 26, 2009

SQL Server Hacking MSDB Tables with Jobs

I've just built a custom replication utility in SSIS to move data from SQL Server to Mysql. It's a vanilla package that exploits the ADO.net api to mysql and standard OLE DB connections to SQL Server. It works just fine on my development box, but when I schedule it to run under SQL Server Agent as a job, it errors with the following error:

"The package execution returned DTSER_SUCCESS (0). Started: 2:20:00 PM Finished: 2:20:06 PM Elapsed: 6 seconds. The return value was unknown. The process exit code was -532459699. The step failed"

However notice it does also show a success, and based on the SSIS log and the results of the job it is succeeding. I hunted Google for a bit, and found some references to authentication, but no definitive resolution. Being I'm on a tight schedule to release this, it's more of an annoyance then an actual issue, I've decided to let it go and focus on more critical issues. Unfortunately the annoyance is causing noise in our monitoring, and if the package really does fail, it will go unnoticed since the job always reports failure. In order to bypass this for the time being I've written a script that's executed in the following step of the job. It simply parses the error message of the previous step and looks for a success of the package. Before going into the script I'd like to ask if you have seen this issue, please post the resolution.


Declare @JobName as
varchar(100)

Declare @message as
varchar(max)

Declare @Job_id as
uniqueidentifier

Declare @Instance_id as
int



--Enter Job Name here

Set @JobName =
'ReplicateNotification'



--Get Message and Job Id of last step

select
top 1 @message =
message,

@Instance_id = instance_id,

@Job_id = sj.Job_id

from msdb.dbo.sysjobhistory sjh

inner
join msdb.dbo.sysjobs sj

on sj.job_id = sjh.job_id

where name = @JobName

order
by instance_id desc






If @message not
like
'%DTSER_SUCCESS%'

Begin

-- Bubble up error to Agent include a Stmt that will cause a failure

print
'Last Step Failed'

select x from x

end

Else

Begin

--Show the Step as a success for good measure

update msdb.dbo.sysjobhistory set run_status = 1

where instance_id = @Instance_id

end



No comments: