Question : Help with sp_start_job

Hi,

I created a sql job using Enterprise manager.  The job is called ScratchJob and all it does is insert a record into a table in the Scratch database.  (this is just a test job).  Ultimately the idea is to call sp_start_job from VB.net code to run a sql job.

[1]
In Query Analyzer, why do I have to call sp_start_job from the msdb database?  I had thought anything prepended with sp_ was a system stored procedure and could be called from anywhere.  For instance, "EXEC sp_help" works from any database but "EXEC sp_start_job" only works when in the msdb database.


[2]
When I connect to msdb and execute from query analyzer...
exec sp_start_job @Job_Name = 'ScratchJob'

... the query executes as expected.  However when I try this from VB.net, I get an exception from SQL:

SqlCommand cmd = new SqlCommand("sp_start_job", cnMsdb);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@job_name", SqlDbType.VarChar, 50).Value = "ScratchJob";

cnScratch.Open();
cmd.ExecuteNonQuery();
cnScratch.Close();

The specified @job_name ('ScratchJob') does not exist.
Exception Details: System.Data.SqlClient.SqlException: The specified @job_name ('ScratchJob') does not exist.
    Line 63:                   cnScratch.Open();
-->Line 64:                   cmd.ExecuteNonQuery();
    Line 65:                   cnScratch.Close();



Answer : Help with sp_start_job

That should have read:
All you should need to do is give the stored procedure sp_start_job Execute permissions to the SQL Server user.
Random Solutions  
 
programming4us programming4us