For an application I need to send personalized invitation emails to end-users every hour. Those users email-addresses, and the rest of their information are in the database.
- All users that have a bit
Planned.IsPlannable
set toTrue
and have aPlanned.DateStart
and aPlanned.DateEnd
between a certain period are available for receiving an email message. - There are about 350 messages to sent every hour.
- All information that must be included in the message is from the Database.
- The application is a .NET4.0 Console application, for data access I use Subsonic3.0.
There are at least two scenarios to choose from: retrieving the appropriate data via a
1:) View something like:
SELECT [Computer].ComputerName,
[User].UserEmail,
[Planned].DateAvailable,
[Planned].DatePlanned
FROM [Computer]
INNER JOIN
[Planned] ON [Computer.ComputerID] = [Planned.ComputerID]
INNER JOIN
[User] ON [Computer].UserID = [User].UserID
WHERE (DATEDIFF(dd, GETDATE(), [Planned.DateAvailable]) < 10)
AND Planned.IsPlannable = 1
and compose, based on the results of this view, the appropriate messages in the C# code of this application.
2:) Compose the entire message on the sql-server in the view and return something like
[EmailTo]
[Subject]
[Body]
Then only iterate trough the results and create MailMessage
Objects from it
in both cases I get the messages like:
foreach (vwGetInvitableComputer u in UserController.GetAllInvitableUsers())
{
// where the usercontroller wraps the Subsonic logic.
// the composition happens here
}
Iterate trough that in the C# code and just compose the mailmessage from that preformatted data.
What scenario is performance and resources wise to choose?
update: There is indeed text manipulation in the database in option 2. However, this is replacing three strings in the messagbody to the CompterName, DateStart and DateEnd.Perhaps, SQL-views are smart enough to spread the performance for this, while the c# code does it "when requested"?