SQL Server: Can I use EXEC to run an external Application?

jnoel10 picture jnoel10 · Oct 19, 2012 · Viewed 16.3k times · Source

Hello and thank you for your time,

I have been searching everywhere online for an example, where a SQL trigger will run an external application, but I have had no luck. All I am seeing is that the EXEC will execute a SQL procedure.

The reason I need this is, I have a SQL Server 2010 with many tables and when an update or insert occurs on certain tables I need my Talend job to run and update the Salesforce tables.

Currently the Talend jobs are running through A task scheduler but the company wants the information to move right away.

Currently this is my code

CREATE TRIGGER UP_ACCOUNT ON ARCUS
AFTER INSERT, UPDATE
AS 

IF(exists(SELECT IDCUST FROM inserted WHERE IDCUST IS NOT NULL))
    BEGIN 
        EXEC [name_of_application]
    END

I still need to do all the checks to make sure this will not crash anything, but the EXEC statement does not seem to want to execute external commands. Any suggestions would be greatly appreciated.

Thank you

Answer

Diego picture Diego · Oct 19, 2012

Complementing the answer on that post. I would never call another app from sql. Several reasons for that, since security until the fact that someone may move the app and you would need to update your trigger, which means you are responsible for the direct communication between trigger and app.

What I would do is make your trigger write to a table and then have a process that monitors that table (reads and delete rows) and than calls the application. I know you have another player but is safer and easier to maintain.