Send message when trigger fires

  • I have a little trigger that updates some stuff when certain criteria is true. No problem. My question is this: what would be the best way to send a message to the client that is caused this trigger to run these updates. Just a little message that in this case certain criteria is true.

     

    Thanks.

  • I would include code that calls a mail program in the trigger to email the user.  This assumes you have or can easily get the users' email address.  I assume you will verify that the email is available proir to attemting to invoke SMTP mail.  See http://www.sqlservercentral.com/scripts/contributions/510.asp  for a script on sending emails from T-SQL .   See http://sqldev.net/xp/sp_smtp_sendmail.htm for an extended stored proc version that also sends email.  I have tried both and they work great.   

    Francis

  • The e-mail message is not going to work. I want an immediate message through windows messaging.

     

     

  • you could use xp_cmdshell and call netsend with it. Although again you'll need to have some way of picking the correct user or computer to send it to.

    Dave

  • Oops I obviously meant net send. Here have an example too

    xp_cmdshell 'net send Bblogs big fluffy pupppies'

    and just in case your trying to forget dos as well!

    NET SEND {name | * | /DOMAIN[:name] | /USERS} message

    Sends messages to other users, computers, or messaging names on the network. The Messenger service must be running to receive messages.

    You can send a message only to an name that is active on the network. If the message is sent to a username, that user must be logged on and running the Messenger service to receive the message.

    name Is the username, computername, or messaging name to send the message to. If the name is a computername that contains blank characters, enclose the alias in quotation marks (" ").

    * Sends the message to all the names in your group.

    /DOMAIN[:name] Sends the message to all the names in the workstation domain. If name is specified, the message is sent to all the names in the specified domain or workgroup.

    /USERS Sends the message to all users connected to the server.

    message Is text to be sent as a message.

    Dave

  • That will work nicely!

    Thank you

  • What would be the best way picking up the name of the client computer that fired the trigger?

     

    Chris

  • Use host_name() or host_id().  

     eg.

    ALTER TRIGGER ordertr

    ON Orders

    FOR INSERT

    AS

    DECLARE @msg varchar(2000)

    SET @msg = 'net send ' + CAST(host_name() AS varchar(30)) + ' test'

      EXEC master.dbo.xp_cmdshell @msg

    Francis

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply