Solved

C#/SQL Server Triggers

Posted on 2004-04-23
6
412 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
ID: 10905475
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
ID: 10905632
0
 
LVL 1

Author Comment

by:bjohns33
ID: 10906542
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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 1

Author Comment

by:bjohns33
ID: 10906573
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
ID: 10909734
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
ID: 10910958
Thanks Joe, I think xp_cmdshell is exactly what I need.

Cheers
Ben
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Winform Module - What is the ASP.Net equiv 2 28
Sort GridView by ID Descending 1 17
Where is this file? 3 25
linq, c# 8 23
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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

829 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