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)
 Exporting data upon INSERT trigger

Author  Topic 

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2010-01-03 : 02:45:24
I'm designing an interface component that will send data via TCP to a listening service. This component needs to be "fired" every time a row is inserted or modified in Tables XYZ. The data that will be sent over is in a special format that would be too difficult to code in T-SQL, and therefore it needs to be coded outside of SQL Server. Besides for managed code/using CLR integration, what are the other possibilities of running this?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-03 : 11:27:31
isnt it better to do this via sql job which fires in frequency? You may use a table to store changed values (deltas) for each period interval and then use this for job to process. Each run will populate a date in a control table which it uses next time to identify delta data.
Go to Top of Page

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2010-01-03 : 12:00:25
It must be done in real-time.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-03 : 12:04:09
quote:
Originally posted by simondeutsch

It must be done in real-time.


ok then wat about calling xp_cmdshell from trigger (though its a bit dirty)
Go to Top of Page

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2010-01-03 : 12:09:40
Doable. Does it run synchronously or asynchronously?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-03 : 12:22:31
it runs synchronously
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-03 : 12:23:13
see this too

http://msdn.microsoft.com/en-us/library/aa260689(SQL.80).aspx
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2010-01-03 : 12:30:02
What you want to look at using is service broker - it is designed to do exactly what you want:

http://msdn.microsoft.com/en-us/library/ms345108(SQL.90).aspx

This will run asynchronously - but, that should be desired as it will not block your application.
Go to Top of Page

simondeutsch
Aged Yak Warrior

547 Posts

Posted - 2010-01-04 : 23:55:03
Service Broker seems very complicated. xp_cmdshell can call an application, but I'm thinking more in line of a .dll.

Has anyone ever worked with sp_OACreate etc.? I'm wondering as to the speed hit when the code is inside a trigger. Also, if the automated object is a COM .exe, perhaps that will run asynchronously?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-01-05 : 00:13:40
I would not recommend xp_cmdshell from a trigger. You'll not only encounter a performance issue by making the transaction too long, but you also run the risk of running into errors that aren't caught in the trigger.

I'd look into Service Broker as Jeff mentioned.

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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -