Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How execute exe file from sql agent or job?

I don't want to hit the database frequently based on page request, so I planned to create a xml file using separate C# coding [exe file] & put in the common path to access from different page/project, which will do the hitting stuff's daily morning, so can you explain how do I execute exe file from sql job or agent by scheduled manner?

My scenario: database table will be updated only once, so I am going for a XML/txt file.

Thanks, S.Venkatesh

like image 307
user1531248 Avatar asked Aug 01 '12 06:08

user1531248


People also ask

How do I run a SQL Agent job?

To start a jobExpand SQL Server Agent, and expand Jobs. Depending on how you want the job to start, do one of the following: If you are working on a single server, or working on a target server, or running a local server job on a master server, right-click the job you want to start, and then click Start Job.

How do you grant permission to run a specific SQL Agent job?

There are only two ways that someone can have permission to execute a SQL Agent job. You must either own the job, or be a member of the role SQLAgentOperatorRole (found in msdb). Unfortunately SQLAgentOperatorRole grants permissions to run any job (among other things).

What is the use of SQL Server Agent jobs?

SQL Server Agent is a Microsoft Windows service that runs scheduled administrative tasks that are called jobs. You can use SQL Server Agent to run T-SQL jobs to rebuild indexes, run corruption checks, and aggregate data in a SQL Server DB instance.


2 Answers

Executable and batch files may be added to a job as step (MSDN Implement Jobs).

  1. Create a job
  2. Add a new step

    2.1 set "Operating system(CmdExec)" as type

    2.2 set the executable path

enter image description here

like image 99
Alberto De Caro Avatar answered Sep 27 '22 21:09

Alberto De Caro


If you must do it in JOB: xp_cmdshell xp_cmdshell execute as nonadmin!

DECLARE @command varchar(8000)
SET @command = 'C:\MyProgram' 
EXEC master..xp_cmdshell @command

But you should shedule task in windows.

like image 31
VoonArt Avatar answered Sep 27 '22 20:09

VoonArt