I'm able to easily get sql server agent job information via the following TSQL:
sp_help_job @job_id=null, @job_name='<My Job Name>',@job_aspect='JOB'
However, when I try to execute this system stored proc in vb.net I get a data type clash error:
cmd = New OleDb.OleDbCommand("sp_help_job", jobConnection)
cmd.CommandType = CommandType.StoredProcedure
''job id value should be set to null - we will filter on the job name...
p1 = New OleDb.OleDbParameter("@Job_id", SqlDbType.UniqueIdentifier)
p1.Direction = ParameterDirection.Input
p1.Value = vbNull
cmd.Parameters.Add(p1)
''job name paramter is the currently running interface, strCurrentPackage...
p2 = New OleDb.OleDbParameter("@job_name", SqlDbType.NVarChar)
p2.Direction = ParameterDirection.Input
p2.Value = strCurrentPackage
cmd.Parameters.Add(p2)
''job aspect value = "JOB" to get only the job info result set...
p3 = New OleDb.OleDbParameter("@job_aspect", SqlDbType.NVarChar)
p3.Direction = ParameterDirection.Input
p3.Value = "JOB"
cmd.Parameters.Add(p3)
jobReader = cmd.ExecuteReader()
The error is "Operand type clash: int is incompatible with uniqueidentifier". I'm not sure where int is coming from, my code isn't using any int data types and all the parameter data types match what the system stored procedure is expecting.
A couple notes on the code: I am using OLEDB because my connection string is passed to me as an OLEDB connection. I am also connecting to the MSDB database.