Solved

C#/SQL Server Triggers

Posted on 2004-04-23
6
408 Views
Last Modified: 2011-10-03
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
0
Comment
Question by:bjohns33
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:Joeisanerd
Comment Utility
what is it that you want the c# code to do? triggers are nice in that it runs on the sql server.

Is your program the only program updating the database?
The code that needs to run when a row is inserted, is it database related?
0
 
LVL 23

Expert Comment

by:rama_krishna580
Comment Utility
0
 
LVL 1

Author Comment

by:bjohns33
Comment Utility
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
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Author Comment

by:bjohns33
Comment Utility
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!
0
 
LVL 9

Accepted Solution

by:
Joeisanerd earned 500 total points
Comment Utility
well you could do that but you could also you use the Sql Server function xp_cmdshell

xp_cmdshell {'command_string'} [, no_output]

in your trigger you could call this and specify a .net command line app that you create that would do the stuff you need.
0
 
LVL 1

Author Comment

by:bjohns33
Comment Utility
Thanks Joe, I think xp_cmdshell is exactly what I need.

Cheers
Ben
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now