Monday, March 19, 2012

Calling an .EXE from a SQL Job?

I'm trying to call a .exe as a Job Step that pulls some data and sends out
custom emails that will execute after a DTS package runs. I tested the EXE
from the command line and it works but I don't know how to call it from with
the Job Step.
I have the step called ''Example of calling an EXE" and set an Operating
System Command (CmdExec) with:
xp_cmdshell 'C:\MyApp\SendAlert.exe' , no_output
When it runs, I check the Windows event and it says:
SQL Server Scheduled Job 'Example of calling an EXE'
(0x0AE46A0A26688D48B29A3C71684CB284) - Status: Failed - Invoked on:
2005-10-27 13:04:45 - Message: The job failed. The Job was invoked by User
sa. The last step to run was step 1 (Calling the EXE).
I have no idea why it's failing when called as a job?One other thing I found while executing the following in query analyzer:
xp_cmdshell 'C:\MyApp\SendAlert.exe'
returns:
"The system cannot find the path specified"
Thanks again.
"Dave" wrote:
> I'm trying to call a .exe as a Job Step that pulls some data and sends out
> custom emails that will execute after a DTS package runs. I tested the EXE
> from the command line and it works but I don't know how to call it from with
> the Job Step.
> I have the step called ''Example of calling an EXE" and set an Operating
> System Command (CmdExec) with:
> xp_cmdshell 'C:\MyApp\SendAlert.exe' , no_output
> When it runs, I check the Windows event and it says:
> SQL Server Scheduled Job 'Example of calling an EXE'
> (0x0AE46A0A26688D48B29A3C71684CB284) - Status: Failed - Invoked on:
> 2005-10-27 13:04:45 - Message: The job failed. The Job was invoked by User
> sa. The last step to run was step 1 (Calling the EXE).
> I have no idea why it's failing when called as a job?|||Dave wrote:
> I'm trying to call a .exe as a Job Step that pulls some data and
> sends out custom emails that will execute after a DTS package runs.
> I tested the EXE from the command line and it works but I don't know
> how to call it from with the Job Step.
> I have the step called ''Example of calling an EXE" and set an
> Operating System Command (CmdExec) with:
> xp_cmdshell 'C:\MyApp\SendAlert.exe' , no_output
> When it runs, I check the Windows event and it says:
> SQL Server Scheduled Job 'Example of calling an EXE'
> (0x0AE46A0A26688D48B29A3C71684CB284) - Status: Failed - Invoked on:
> 2005-10-27 13:04:45 - Message: The job failed. The Job was invoked
> by User sa. The last step to run was step 1 (Calling the EXE).
> I have no idea why it's failing when called as a job?
xp_cmdshell is in the master database. You need to fully qualify the
name if you are not in master:
exec master..xp_cmdshell 'dir'
Also, you need to make sure the SQL Server service account has access to
the folder where you placed the EXE. If not, you need to grant the
account access of move the file(s) to a folder where the account has
access.
David Gugick
Quest Software
www.imceda.com
www.quest.com|||Dave
You can also run cmd commands from SQL jobs In the same job you are running
DTS
--
Paul Zanbaka
DBA, Programmer Analyst
"David Gugick" wrote:
> Dave wrote:
> > I'm trying to call a .exe as a Job Step that pulls some data and
> > sends out custom emails that will execute after a DTS package runs.
> > I tested the EXE from the command line and it works but I don't know
> > how to call it from with the Job Step.
> >
> > I have the step called ''Example of calling an EXE" and set an
> > Operating System Command (CmdExec) with:
> >
> > xp_cmdshell 'C:\MyApp\SendAlert.exe' , no_output
> >
> > When it runs, I check the Windows event and it says:
> >
> > SQL Server Scheduled Job 'Example of calling an EXE'
> > (0x0AE46A0A26688D48B29A3C71684CB284) - Status: Failed - Invoked on:
> > 2005-10-27 13:04:45 - Message: The job failed. The Job was invoked
> > by User sa. The last step to run was step 1 (Calling the EXE).
> >
> > I have no idea why it's failing when called as a job?
> xp_cmdshell is in the master database. You need to fully qualify the
> name if you are not in master:
> exec master..xp_cmdshell 'dir'
> Also, you need to make sure the SQL Server service account has access to
> the folder where you placed the EXE. If not, you need to grant the
> account access of move the file(s) to a folder where the account has
> access.
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
>

No comments:

Post a Comment