Search code examples
vb.netsql-server-2000sql-job

Reading the contents of a SQL Server job in VB.NET


I am writing an application that will call a SQL Server job on all our client's systems.

I'm able to execute it, and wait until it's finished. It has an output file that's save location is hard coded into the job however, and this is not the same location on all client's.

Since the job is identical on systems minus this one value, I want my code to read in the script of the job and parse out the location.

I'm having trouble figuring out how to get the actual text of the job itself.

Is this possible in .NET? If so, how?


Solution

  • You can get the contents of the job by using the following query:

    SELECT [command]
    FROM msdb.dbo.sysjobs job JOIN msdb.dbo.sysjobsteps steps
    ON job.job_id = steps.job_id 
    WHERE [name] = 'YourJobName'
    

    From there, just create a recordset in VB.NET and use the query above.