Question

I have a SQL Server database which is shared between several ASP.NET (VB.NET) websites, the database has a table which stores customer enquiries - I wish to provide email notifications informing of new enquiries to relevent people within the organisation (and possibly put some of the enquiry data into the body of the email). Please could someone outline my options in terms of how this could be implemented?

My thoughts are:

  1. SQLMail
  2. Database Mail
  3. VB.NET Stored Procedure using System.Net.Mail library?
  4. Other options?

Option 3 seems desirable because I know how to do this in VB.NET and it is trivial.

  • What are my other options?
  • What are the caveats?
  • Can I do this in real-time i.e. a trigger (the volume of inserts is low)?
  • or is it vital that this is done in a batch i.e. a job?

Any help very welcome! Thanks.

Was it helpful?

Solution

Between 1), 2) and 3) the only one worth considering is 2). 1) is a stillborn, using a deprecated feature notorious for it's problems and issues. 3) is a bad idea because it breaks transactional consistency (the SMTP mail is sent even if the insert rolled back) and is a performance hog as the caller (presumably your web page being rendered) has to wait until the SMTP exchange completion (ie. is synchronous). Only 2) offers transactional consistency and is asynchronous (does not block the caller until the SMTP completes).

Normally though such task is better delegated to a Reporting Services task. You would create a Data-Driven subscription with an email delivery. This works out-of-the-box, no need to reinvent the wheel.

OTHER TIPS

I have worked with a similar situation to this, and the solution I went with was to have a C# windows service checking a SQL server job queue every minute. This job queue would include jobs such as send an email. You could then use a TRIGGER on your table to insert a new "Email Alert" job, that would get picked up by the next cycle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top