Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7412617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:34:08+00:00 2026-05-29T06:34:08+00:00

Well my windows service has to send out automated emails when the sql database

  • 0

Well my windows service has to send out automated emails when the sql database has been updated.

How Exactly would i go about doing this? any code or tutorials would really help me

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:34:08+00:00Added an answer on May 29, 2026 at 6:34 am

    Solution 1 – Using sp_send_dbmail

    Here is an example of creating a trigger that sends an email when an INSERT/UPDATE/DELETE event occurs on a specific table:

    USE AdventureWorks2008R2;
    GO
    IF OBJECT_ID ('Sales.reminder2','TR') IS NOT NULL
        DROP TRIGGER Sales.reminder2;
    GO
    CREATE TRIGGER reminder2
    ON Sales.Customer
    AFTER INSERT, UPDATE, DELETE 
    AS
       EXEC msdb.dbo.sp_send_dbmail
            @profile_name = 'AdventureWorks2008R2 Administrator',
            @recipients = 'danw@Adventure-Works.com',
            @body = 'Don''t forget to print a report for the sales force.',
            @subject = 'Reminder';
    GO
    

    Source: http://msdn.microsoft.com/en-us/library/ms189799.aspx

    sp_send_dbmail was introduced in SQL Server 2005. More info: http://msdn.microsoft.com/en-us/library/ms190307.aspx

    Note:

    Before use, Database Mail must be enabled using the Database Mail
    Configuration Wizard, the SQL Server Surface Area Configuration tool,
    or sp_configure.

    Solution 2 – Using xp_cmdshell

    If you can’t set up Database Mail you have another option: xp_cmdshell.
    With it you can run command line commands within SQL statements e.g. a small email sending tool.

    This one is a small example how to send emails using System.Net.Mail in a C# application: http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx

    How to use xp_cmdshell: http://msdn.microsoft.com/en-us/library/aa260689%28v=sql.80%29.aspx

    So you create a small C# console app that sends email then you execute it with xp_cmdshell right from your SQL statement.

    Solution 3 – Using a windows service (as he wants)

    A Windows Service can’t determine by itself whether a rows gets updated in an MSSQL database. You need to log the changes. To do so you may create an trigger for a specific table to record changes. By recording changes I mean inserting a new row into a log table withing the trigger like this:

    USE MyDatabase;
    GO
    IF OBJECT_ID ('Products.TRRowUpdated','TR') IS NOT NULL
        DROP TRIGGER Products.TRRowUpdated;
    GO
    CREATE TRIGGER TRRowUpdated
    ON Products
    AFTER INSERT, UPDATE, DELETE 
    AS
       INSERT INTO log ('Message', 'Date') VALUES ('Products table got modified', GETTIME())
    GO
    

    Creating a Windows Service Project is as easy as creating a Console Application using Visual Studio.

    Your service will then read the ‘log’ table like every minute and send out emails if there were any rows in it (and deletes them of course).

    It is possible to determine what kind of change happened: INSERT, UPDATE or DELETE. See the comments on this site for more details: http://msdn.microsoft.com/en-us/library/ms189799.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm well into implementing a REST service (on a Windows CE platform if that
I have a windows setup project that installs a service. All works well except
I have a Windows service that has a number of threads that all need
My product has several components: ASP.NET, Windows Forms App and Windows Service. 95% or
I am using LinqToEntitiesDomainService to connect to a SQL Server Database. This requires Windows
Well, I have created a new windows service and the install from Visual Studio.
Well, I'm sure this question has been asked before but I'm yet to find
Well behaved windows programs need to allow users to save their work when they
My application is a rather well behaved Windows citizen, so when I ported it
Can someone recommend a secure FTP implementation that works well on Windows Server 2000?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.