bjohns33
asked on
C#/SQL Server Triggers
Hi all
I want to run some C# code when a record is added to a SQL Server table - what's the best way to achieve this?
Cheers
Ben
I want to run some C# code when a record is added to a SQL Server table - what's the best way to achieve this?
Cheers
Ben
ASKER
Hi Joe
There's an external process which is pretty much black-boxed that will insert records in to this database. When the record appears I want the .NET event to be run. This will have some interaction with the database - it will basically create an email, add some attachments (which are defined in the inserted record), and send it to the email address specified in the inserted record.
I've looked at Notification Services, but these a) seem to be overkill for this, b) don't support attachments out of the box and c) are a pain in the arse to configure.
So basically, I want a trigger that runs a program. All of it will be on the same server.
Rama
Both of those links relate to creating standard database triggers, which are self-contained within the database - this needs to call an external programme as a result of the trigger.
Thanks
Ben
There's an external process which is pretty much black-boxed that will insert records in to this database. When the record appears I want the .NET event to be run. This will have some interaction with the database - it will basically create an email, add some attachments (which are defined in the inserted record), and send it to the email address specified in the inserted record.
I've looked at Notification Services, but these a) seem to be overkill for this, b) don't support attachments out of the box and c) are a pain in the arse to configure.
So basically, I want a trigger that runs a program. All of it will be on the same server.
Rama
Both of those links relate to creating standard database triggers, which are self-contained within the database - this needs to call an external programme as a result of the trigger.
Thanks
Ben
ASKER
A brute force solution would be to write a service that polls a view in the database every x seconds that just shows unprocessed records, but while this would be simple, it doesn't seem very elegant!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Joe, I think xp_cmdshell is exactly what I need.
Cheers
Ben
Cheers
Ben
Is your program the only program updating the database?
The code that needs to run when a row is inserted, is it database related?