views:

825

answers:

3

I need to have a process that compiles daily data into an PDF that will be attached into an email. I have already used MSSQL to send emails in the application being developed and would like to continue to use MSSQL as the email processor.

In my research, I have found that this can be achieved by creating a Windows Service. But, since I am only really wanting this process to run once a day; keeping an always active Windows Service seems to be overkill.

I have never used task scheduler to run a self-built application. I want to make sure that I am going about it the correct way. As I understand, I will have to...

  1. Create a new project (Project X) in Visual Studio
  2. Program (Project X) to generate the PDF and interact with MSSQL to send the email
  3. Build (Project X) into an EXE
  4. Schedule the EXE using Task Scheduler to run on whatever schedule I need.

Are there any security aspects I should be concerned about? Only ones I can think of are encrypting my MSSQL connection string; and, of course, keeping the EXE out of the web accessible directory the web app resides in.

Thank you in advance for the help/confirmation as I know some will think this is a silly question.

+1  A: 

The only thing I can see you haven't considered is the identity under which Task Scheduler will run your EXE, but that shouldn't be too much of a concern seeing how you seem to control everything in the environment.

Esteban Araya
A: 

If you want to build a Windows Service, you can set it to start when the server (that the database resides on) starts. I'd have an external tracking system for sending the emails tho, possibly in a separate database. When the server starts, your service starts too. Service checks if an email has been sent today. If not, build email, send email, then mark it in the log (the db table I assume). Then have the service sleep for 24 hours, then have it check again (using an event). Repeat.

jcollum
+1  A: 

As Esteban notes: will this just be running under your account and will you just stay signed on to the machine? If so, that is your biggest security risk. You can use a screen saver to force a login prompt and it is largely true that this is no less secure than logging out. However, I doubt that this would be considered "best practices."

I would consider building a Windows Service that simply wakes up once a day. They are truly not very difficult to build although you'll want to be sure to have a good testing mechanism (an independent class that you compile into a Unit-testable dll is a good idea) since testing them once they are running is very difficult. But don't let the "mystery" of service apps or the idea of resource usage put you off. You'll be surprised how easy they are. As far as resources go...you are spending more resources keeping a full Winforms app running!

Mark Brittingham