db********@yahoo.com (Dan Bart) wrote in message news:<fa**************************@posting.google. com>...
I need to execute xp_cmdshell in a trigger and pass a command line
parameter to the .exe program
i.e. I have a .exe program c:\program files\savedata.exe
In the trigger I have a parameter @Id bigint
I need to pass the parameter @Id to savedata.exe
In the trigger, I am trying
EXEC master..xp_cmdshell 'cmd.exe /C "c:\program files\savedata.exe "'
+ CAST(@Id as varchar)
BUT this does not work.
Can someone please help me with how to do this?
Thanks,
db
Calling an external program from a trigger is usually a bad idea - if
the external program takes a long time to run, hangs, or does
something unexpected, you can easily block other clients. A better
plan is to insert your @Id values into a separate table, then have a
scheduled job which processes the values at regular intervals - this
won't block or otherwise impact the main processing.
If you really want to do it, you should rewrite your command like
this:
declare @cmd varchar(8000)
set @cmd = 'cmd.exe /C "c:\program files\savedata.exe "' + CAST(@Id as
varchar)
EXEC master..xp_cmdshell @cmd
Simon