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.
| Author |
Topic |
|
Xiphias70
Starting Member
4 Posts |
Posted - 2006-01-13 : 15:15:46
|
| I was wondering if anyone out there has any code to automate the execution of a SQL Job? The purpose of this is to run the vbs file locally (on local machine), connect to SQL server and run the SQL Job. I would appreciate this help. While I can run DTS packages, I am unable to "find" the SQL object to run the SQL Job. Again thanks. |
|
|
Xiphias70
Starting Member
4 Posts |
Posted - 2006-01-17 : 08:39:46
|
Never mind. I finally got around to finding the SQL-DMO objects and how to "execute" a job when I want to. If anyone cares, here is the code On Error Goto 0: Main()sub Main() Set objSQL = CreateObject("SQLDMO.SQLServer") Set WshShell = CreateObject("WScript.Shell")' Leave as trusted connection or undo the commented section' to provide a sql login id and password objSQL.LoginSecure = True' --- or use the following for non-trusted connections --- 'objSQL.LoginSecure = False 'objSQL.Login = "<login>" 'objSQL.Password = "<password>"' ---' Change to match the name of your SQL server objSQL.Connect "<sql server name>" Set objJob = objSQL.JobServer For each job in objJob.Jobs if instr(1,job.Name,"<job pk string>") > 0 then msgbox job.Name 'job.Start end if Nextmsgbox "Execution of VBS completed...Job Started.."End Sub' -- End Main Code Execution -- |
 |
|
|
|
|
|