August 5, 2009 at 6:21 am
Hi!
I have a table where the users are always adding information. I'll like to show in my application a message to all them every time a row is inserted or updated.
In Interbase there is a "event" process that does this communication.
But, here in SQL Server, is there a "event" like that? How could I send a message to all clients when that table changes?
August 5, 2009 at 6:27 am
Two possibilities come to my mind:
1) You could send a mail to all users from a trigger.
2) Insert the rows into a message table from a trigger and then read, notify and delete rows from the app side in a recurring task
Hope this helps
Gianluca
-- Gianluca Sartori
August 5, 2009 at 6:32 am
well it can be done...but the better question is do you really want to....you might not after you think through the ramifications...
lets assume that someone adds a new record and saves, then edits a record, saves, then edits it a little more, then saves again...all within say, ten seconds.(this is a very common data entry situation...heck, i re-edit my forum posts a couple of times after the original posting, after re-reading and reviewing the post)
do you really want to send three emails saying data has changed within that time? how often do changes to this data occur that you want to alert a group of people?
ok now the technical aspects:
in SQl 2005, the procedure msdb.dbo.sp_send_dbmail is asyncronous, meaning the it doesn't wait to completely send the email before it returns control back tot eh calling procedure. that means if you use it in a trigger whent eh event occurs, then you won't suffer performance wise.
rather than a trigger, I'd suggest tracking which items changed, and polling whether enough changes have occured to justify sending an email that identifies all the changes up to a certain point...more like a once a day notification, or once a week, rather than instantaneously in a trigger.
-=Edit=- Gianluca and I are on the exact same page...
Lowell
August 5, 2009 at 6:42 am
Thanks for answer!
But I don´t wanna send a e-mail: I just need send a "event" that can be captured by Delphi. I have a toolbar on my program that changes the buttons color: each color is a status of a specific row. I wanna that toolbar read this unique table all time it changes, I don´t wanna a timer that reads at a specific time, I wanna know in my Delphi program that a "event" happened and so I'll read that table again.
Is this possible?
August 5, 2009 at 7:03 am
It can't be done that simply. There's no such feature in SQL Server. Plenty of workarounds, but no such feature.
-- Gianluca Sartori
August 5, 2009 at 7:15 am
Yeah, SQL Server is really stateless in that situation, like a web page would be...unless you poll for a new snapshot of data,and compare against your local cache to see if they are different, there is no way to determine that a change occurred.
Lowell
August 5, 2009 at 11:35 pm
Gianluca Sartori (8/5/2009)
Two possibilities come to my mind:1) You could send a mail to all users from a trigger.
2) Insert the rows into a message table from a trigger and then read, notify and delete rows from the app side in a recurring task
Hope this helps
Gianluca
The bad part about #1 above is if there is any latency or the email server is down... BOOM!
I cheat on things like this... xp_CmdShell to a batch file with a NETSEND.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 6, 2009 at 1:01 am
Jeff Moden (8/5/2009)
I cheat on things like this... xp_CmdShell to a batch file with a NETSEND.
LOL!
Haven't heard of NET SEND in the last 5 years!
It's disabled by default in every windows installation >= XP SP2!
-- Gianluca Sartori
August 6, 2009 at 12:36 pm
Gianluca Sartori (8/6/2009)
Jeff Moden (8/5/2009)
I cheat on things like this... xp_CmdShell to a batch file with a NETSEND.LOL!
Haven't heard of NET SEND in the last 5 years!
It's disabled by default in every windows installation >= XP SP2!
I love things like Net Send... it all falls into the category of (pardon the poetic license), "You can't teach a new dog old tricks." 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
August 7, 2009 at 9:54 am
I am forced to use Vista at work - I miss NET SEND!
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
August 11, 2009 at 12:00 pm
ok now the technical aspects:
in SQl 2005, the procedure msdb.dbo.sp_send_dbmail is asyncronous, meaning the it doesn't wait to completely send the email before it returns control back tot eh calling procedure. that means if you use it in a trigger whent eh event occurs, then you won't suffer performance wise.
rather than a trigger, I'd suggest tracking which items changed, and polling whether enough changes have occured to justify sending an email that identifies all the changes up to a certain point...more like a once a day notification, or once a week, rather than instantaneously in a trigger.
August 12, 2009 at 9:15 am
Have a look at this:
http://www.simple-talk.com/sql/sql-server-2005/using-and-monitoring-sql-2005-query-notification/
I tried it some time ago but could never get it to work, you might have more luck.
It all depends whether you can reference the .NET assemblies in Delphi (I was using C# so not a problem), never used Delphi so I'm no use there, sorry.
I just thought it may give you somewhere to start.
This may help too: http://www.google.com/search?q=Query+Notifications
Good luck
Nigel
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply