4
votes

I have a MVC website that gets published to Azure where it uses an Azure SQL Database.

The time has come where we need to run a scheduled task to send SMS reminders. I was under the impression that Azure Web Jobs was a good fit for this but am having some issues getting it up and running.

I have added a console app to my website solution and referenced by EF data model from the console app (which I would like to publish as a web job).

The current console app looks as follows:

 class Program
{
    static void Main(string[] args)
    {
        JobHost host = new JobHost();
        host.RunAndBlock();
    }

    public static void ProcessNotifications()
    {
        var uow = new KirkleesDatabase.DAL.UnitOfWork();
        uow.CommunicationRepository.SendPALSAppointmentReminders();
    }

}

Running the console app will then throw the exception:

Additional information: User account connection string is missing. This can be set via the 'AzureJobsData' connection string or via the constructor.

This suggests that the Web Job is specifically looking for a connection string that points at a storage account. However, I would like the web job to query an Azure database rather than work with storage.

Is this doable?

Thanks,

3
the error message suggests that the WebJob is looking for a storage account connection string for triggers only. Accessing .NET SQL APIs for storage within a WebJob is fine.Matthew

3 Answers

2
votes

As Victor wrote, the sdk events are triggered by blobs, queues and tables.
A simple solution for your need: write a console application with a pollig approach. No sdk needed. Details at the beginning of http://blog.amitapple.com/post/73574681678/git-deploy-console-app/

while(true)
{
  if ("isthereworktodo?")
  {
    var uow = new KirkleesDatabase.DAL.UnitOfWork();
    uow.CommunicationRepository.SendPALSAppointmentReminders();
  }
  Thread.Sleep(10000);  // set an appropriate sleep interval
}
1
votes

Unfortunately the WebJobs SDK does not support SQL databases as triggers. For triggers, it only supports Azure Storage (blobs, queues and tables).

You can access Azure SQL Databases from the web job as demonstrated in this answer.

0
votes

To create a web job you don't have to use the webjobs sdk, you can use several types of executables (.exe, .cmd, .js, .php, .py, ...).

Try using this new visual studio add-on: http://visualstudiogallery.msdn.microsoft.com/f4824551-2660-4afa-aba1-1fcc1673c3d0, follow the steps there to link between your web application and your console application which will be deployed as a webjob when published to your Azure site.