osmansays,
Combine a trigger and a stored procedure to send a email on updates
--------------------------------
Procedure like :
Create Procedure sp_SMTPMail
@.SenderName varchar(100),
@.SenderAddress varchar(100),
@.RecipientName varchar(100),
@.RecipientAddress varchar(100),
@.Subject varchar(200),
@.Body varchar(8000),
@.MailServer varchar(100) = 'localhost'
AS
SET nocount on
declare @.oMail int
declare @.resultcode int
EXEC @.resultcode = sp_OACreate 'SMTPsvg.Mailer', @.oMail OUT
if @.resultcode = 0
BEGIN
EXEC @.resultcode = sp_OASetProperty @.oMail, 'RemoteHost', @.mailserver
EXEC @.resultcode = sp_OASetProperty @.oMail, 'FromName', @.SenderName
EXEC @.resultcode = sp_OASetProperty @.oMail, 'FromAddress', @.SenderAddress
EXEC @.resultcode = sp_OAMethod @.oMail, 'AddRecipient', NULL, @.RecipientName, @.RecipientAddress
EXEC @.resultcode = sp_OASetProperty @.oMail, 'Subject', @.Subject
EXEC @.resultcode = sp_OASetProperty @.oMail, 'BodyText', @.Body
EXEC @.resultcode = sp_OAMethod @.oMail, 'SendMail', NULL
EXEC sp_OADestroy @.oMail
END
SET nocount off
--------------------------------
Trigger like :
CREATE TRIGGER trgDataChanged on tblData
AFTER UPDATE
AS
BEGIN
exec sp_SMTPMail @.SenderName='me', @.SenderAddress='me@.somewhere.com', @.RecipientName = 'Someone', @.RecipientAddress = 'someone@.someplace.com', @.Subject='SQL Data Change', @.body='data in table tblData has been changed'
END
--------------------------------
If you also want to track the changes you can either translate the query to simple data or show the data that is changed but to view that you need to walk through the recordset with for instance a cursor.
Peter
Showing posts with label updated. Show all posts
Showing posts with label updated. Show all posts
Friday, March 23, 2012
How can I be notified when record is updated
I want to build an windows application by using a visual C# to Notify the user that his data in the database had been changed ..such like "New Message In Your Mail Box Alert"..So I need to know if there is way that to let the SQL Server send a notify (just like Trigger) ..
Monday, March 19, 2012
How can client applications know if a table has been changed
If you're asking about a way in which a client application can be
notified of new or even updated records on the server, then you may want
to check out Notification Services. The provided Realtor sample provides
a simple example.
HTH...
Joe Webb
SQL Server MVP
~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/t...il/-/0972688811
Tibor Karaszi wrote:
>
> Or, in the UPDATE, you include the buffered rowversion value in the WHERE
clause (with the primary
> key value). If the update modifies zero rows, you know that either the row
was deleted or it was
> updated.
>LOL!!! :)
HTH...
Joe Webb
SQL Server MVP
~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/t...il/-/0972688811
Tibor Karaszi wrote:
> LOL. First time I noticed your signature, Joe, I thought that SQLNS referr
ed to the SQL-NS API with
> which you can re-use dialogs from EM in your client app. :-)
>
notified of new or even updated records on the server, then you may want
to check out Notification Services. The provided Realtor sample provides
a simple example.
HTH...
Joe Webb
SQL Server MVP
~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/t...il/-/0972688811
Tibor Karaszi wrote:
>
> Or, in the UPDATE, you include the buffered rowversion value in the WHERE
clause (with the primary
> key value). If the update modifies zero rows, you know that either the row
was deleted or it was
> updated.
>LOL!!! :)
HTH...
Joe Webb
SQL Server MVP
~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/t...il/-/0972688811
Tibor Karaszi wrote:
> LOL. First time I noticed your signature, Joe, I thought that SQLNS referr
ed to the SQL-NS API with
> which you can re-use dialogs from EM in your client app. :-)
>
Labels:
application,
applications,
asking,
benotified,
client,
database,
microsoft,
mysql,
oracle,
records,
server,
sql,
table,
updated,
wantto
Subscribe to:
Posts (Atom)