Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C#/SQL Server Triggers

Posted on 2004-04-23
6
Medium Priority
?
426 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 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

972 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