Groups | Blog | Home
all groups > sql server connect > june 2007 >

sql server connect : Trigger a .EXE from SQL Server


Jon Rowlan
6/9/2007 12:00:00 AM
Is it possible to trigger a .EXE program to run on a Row insertion ...

I want to run an .EXE program whenever a new row is inserted to create a
directory somewhere on the server.

I know that there are triggers that I can use but these seem to be to
execute SQL statements ...

many thanks all,

jON

Russell Fields
6/9/2007 12:00:00 AM
Jon,

In your trigger, provided that it is enabled for non-sysadmin use, you can
use the xp_cmdshell procedure to issue an operating system command line
statement. This will, of course, cause a small delay in the completion of
your insert statement. (But xp_cmdshell has security issues.)

If you can stand a minute or two of asynchronous delay you might do
something like the following.
1. Create a SQL Agent job to run the EXE.
2. Post enough data in the inserted table or in another table if necessary
to describe with directories still need to be created.
3. From your trigger issue an sp_start_job 'jobname'

This will run asynchronously from the trigger, allowing the trigger to
complete. If you are using SQL Server 2005 you can grant the job the needed
security context using a SQL Agent proxy account.

RLF
[quoted text, click to view]

Rick Byham, (MSFT)
6/11/2007 9:51:45 AM
Running out of process actions like the file system creation is discouraged
in a trigger. A better method, would be to execute the insert through a
stored procedure, with the directory creation and the insert being called in
some order. Then the lock held on the insert will be much shorter, resulting
in less chance of bogging down the whole operation.
--
Rick Byham (MSFT)
This posting is provided "AS IS" with no warranties, and confers no rights.

[quoted text, click to view]
AddThis Social Bookmark Button