Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch that a trigger has been fired on sql server

I have a table on SQL and when there is an insert to this table I want to print this inserted data.

What I am thinking in:

  1. Create a trigger on that table.
  2. Handle the printing event on c# after the trigger works.

My problem

I don't know what is the name of the feature that makes a c# code fires when a trigger fires.

Can you help me with this issue, please?

like image 377
RE RE RE RE Avatar asked Nov 10 '22 02:11

RE RE RE RE


1 Answers

There are several ways of solving this problem, and the soluton depends on the system architecture (permissions, accesibility), and the knowledge to implement it.

There are basically this options, which are affected by the pointed out factors:

  • printing directly from the inserting application or notifying from the inserting application: can you change that application? is it possible to comunicate from tha application to the printing application. (It could be implemented, for example, with WCF)
  • sql dependencies (SQL Notification request): the printing application should create and subscribe to a sql dependency: do you have permission to create the dependencies in the server?
  • polling: is the quick & dirty solution: use a "timer" to check if there is new data and print it when available

The last solution is the one that will pose the least problems. It's not "smart" but it's very easy to implement. You can adjust the polling period depending on the expected number of messages and the "real-time" requirements of the pringing application.

like image 179
JotaBe Avatar answered Nov 14 '22 23:11

JotaBe