Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Disabling Job using VBScript

Author  Topic 

badkneecap
Starting Member

10 Posts

Posted - 2008-06-06 : 16:42:30
I have an SQL job that runs a .vbs script. It has the following code:

Cmd2.ActiveConnection = Conn2
Cmd2.CommandText = "USE msdb EXEC sp_update_job @job_name = 'Email Download',@enabled = 0"
Cmd2.CommandType = 1
Cmd2.Execute()

It's not disabling the job. If I execute in Query Analyzer, it works. I'm thinking it might be a permissions issue. Any suggestions?

TIA

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-06 : 16:48:17
You should be receiving an exception if it's a permissions problem. Have you run SQL Profiler to see what's going on?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

badkneecap
Starting Member

10 Posts

Posted - 2008-06-06 : 17:15:46
I am not that good with SQL. I know just enough to get by. I wouldn't know where to begin. It's a .vbs file and I'm not sure how I can trace through it.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-06 : 17:21:53
SQL Profiler is a SQL Server tool that allows you to trace SQL Server activity. If you have the client tools installed and didn't uncheck SQL Profiler, then you've got it on your machine. Open it up, connect to your server, add SP:Completed (in Stored Procedures collection) and Exception (in Errors and Warnings collection) to the trace, start the trace, run your vbs, stop the trace, check the trace for what happened.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

badkneecap
Starting Member

10 Posts

Posted - 2008-06-06 : 19:48:40
Well, I followed what you said and could not find anything in the trace.

What should I be looking for?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-07 : 00:33:15
Did you see an exception?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

badkneecap
Starting Member

10 Posts

Posted - 2008-06-10 : 20:59:26
There are groups of exceptions that all show the same message:

Exception Error: 208, Severity: 16, State: 0 Microsoft SQL Server Management Studio Administrator UTROPICM-SQL-47\Administrator

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-11 : 11:34:31
208 is the invalid object error.

Remove the USE msdb from your code and instead do this EXEC msdb.dbo.sp_update_job...

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

badkneecap
Starting Member

10 Posts

Posted - 2008-06-11 : 12:37:24
I tried again, and no luck.

But I ran the script manually to see what would happen. I got an error message that might shed some light. I'm logged in as the administrator when I ran the script, I got:

EXECUTE permission denied on object 'sp_update_job', database 'msdb', schema 'dbo'

Not sure which permissions I need to update and how.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-11 : 12:47:22
It is simple to find out what permissions are needed. Just open up SQL Server Books Online, type in sp_update_job and head to the permissions section.

From BOL:
quote:

Permissions
By default, members of the sysadmin fixed server role can execute this stored procedure. Other users must be granted one of the following SQL Server Agent fixed database roles in the msdb database:

SQLAgentUserRole


SQLAgentReaderRole


SQLAgentOperatorRole


For details about the permissions of these roles, see SQL Server Agent Fixed Database Roles.

Only members of sysadmin can use this stored procedure to edit the attributes of jobs that are owned by other users.



Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

badkneecap
Starting Member

10 Posts

Posted - 2008-06-11 : 13:26:34
That worked! The user I was loggin in as needed to be added to the right server role.

Thanks again.
Go to Top of Page
   

- Advertisement -