it is possible to detect a trigger of a table from vb.net? I need to send email when you enter a new order in the administrative system, I have placed a trigger in the orders table, but I need to know when a log entry to send email automatically from vb app. I use a MS SQL Express 2012 and VB NET 2013. Thank you for any help.
-
I'd suggest you have the trigger create a new entry in a work table. Then have your VB app scan the work table for new, unworked entries however often you want to check it. When it finds unworked entries, it works it, sending and email, and when finished, updates the entry so it will not rework the same entry. Makes trigger run quickly, as all it does is insert a record into the work table holding the vb app's email work queue.– StarPilotCommented May 16, 2015 at 0:14
-
Client-side programs aren't aware of the existence of triggers, that's not what they're supposed to do. There are two options, send the mail from the trigger itself (possible, but not recommended at all) or send it client-side immediately after the DB operation succeeded.– AlejandroCommented May 16, 2015 at 0:47
-
Hi StarPilot, I did exactly what you suggest, but how I can do to know there is a new record unworked? With a timer, an infite loop? But I can do anything more on the app, I have no control. Any suggestions? Thank you– CapangaCommented May 16, 2015 at 16:03
-
Hi Alejandro, my problem is that I dont know when the DB operation where done. I made a Trigger Insert that inserts a new record in another table to log the operation, but how I can fire the app to look the table for unworked registers? will say, once each minute. Have to use a timer or what would be appropiate to do the work and at the same time let me do another thing with the app, like change params, make queries to see how its working and others, and dont get the app freeze.– CapangaCommented May 16, 2015 at 16:12
2 Answers
You can't do it through a trigger, there is a platform called notification services which is designed to be used with this.
https://technet.microsoft.com/en-us/library/ms171247(v=sql.90).aspx
Yes, the link says 2005 but it still works with 2012.
-
-
I have not, as I'm not a programmer anymore but more of a DBA :) I know it does work, though, as I've witnessed demos.– user3777201Commented May 16, 2015 at 3:58
-
I seem to be a bit of both these days. Hopefully get a chance to try it out. I have always wanted something like this. Thanks for the share! Commented May 16, 2015 at 4:25
-
Hi Sean Gallardy, Im looking how to do this with notification services but, Im a vb 2013 beginner and its a little bit hard for me this way, all the code is in C#, I will try.– CapangaCommented May 16, 2015 at 16:06
Trigger are internal to their respective DB for internal work(it's like a stored procedure-Insert/Update/Delete). They are not things you can listen for in a VB app.
However something you can do is make a WebService
that you use to access the database and when that routine runs in the service you can then send an email in code from that point.