Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Long Running Process from a trigger

Author  Topic 

zyd
Starting Member

2 Posts

Posted - 2008-09-24 : 17:42:16
Hi. This is my first time in forum and i hope i can help and be helped in SQL topics.
This time i'm here looking for an answer to a seemly easy issue but one that has made me lost my nerves.
This is the situation:
I have an application in a .exe module. That .exe is written in c# and running in .NET 2.0. I want that .exe to run after ona specific table has been modified. That's it. The process takes 2 minutes give or take to fulfill its work.
Obviously this has to be done with a trigger. until now i've tried the following approaches.
1. In the trigger i use this instruction:
EXEC master..xp_cmdshell 'C:\windows\Microsoft.NET\Framework\v2.0.50727\App.exe'
this causes sql to throw a timeout exception.

2. Wrap all of my C# code in one method call and put that in it's own thread. new Thread(myMethod).Start() with the same result as above

3. Wrap all of my code in one method call and use ThreadPool to start it. It's just never called. I don't understand why but it is never executed, I have log files to watch for errors but they are never created wich implies that the process is never executed.

4. Put the sql code EXEC master..xp_cmdshell 'C:\windows\Microsoft.NET\Framework\v2.0.50727\App.exe' in a stored procedure and use SQL queues to queue its execution. This is the weirdest of alla, in very rare ocasions it is executed but in most ocasions nothing happens

I have use all the alternatives that my knowledge gives me. Could somebody propose new approches, or tell me why my approches haven't worked.

It should be noted that if i write this EXEC master..xp_cmdshell 'C:\windows\Microsoft.NET\Framework\v2.0.50727\App.exe' in a query window with the same user used to make the insertion in the table, everything happens normally, i mean there are no permissions issues.

Thanks in advance.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-09-24 : 17:43:58
It is a very bad idea to launch an executable via a trigger. If the executable ever hangs, the trigger will hang the transaction.

Instead of doing this, you should put the executable in a job. When the trigger fires, write to a table that the job will read every minute. When the job notices the row in the table, it'll fire the executable.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

zyd
Starting Member

2 Posts

Posted - 2008-09-24 : 17:56:14

Thanks for your reply.

In a normal (non-test) environment this process will be lunched less than 4 times a monht, but it doesn't follow a normal distribution. It could be lunched 4 times one day, or 0 times a month.
This job that is reading the temporal table every minute, how many resources would use?
From the server utilization point of view, is this a good option?

Thanks.
Luis
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-09-24 : 18:30:09
reading a small table like that every minute is trivial. server wouldn't even notice.


elsasoft.org
Go to Top of Page
   

- Advertisement -