Azure Web Job - How to connect to an Azure MS SQL database?

I have an MVC website that publishes in Azure, where it uses an Azure SQL database.

The time has come when we need to run a scheduled task to send SMS reminders. I got the impression that Azure Web Jobs is great for this, but I am having problems starting up.

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

The current console application is 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 application then throws an exception:

Additional Information: The user account connection string is missing. This can be set via the AzureJobsData connection string or through the constructor.

This indicates that the web job is specifically looking for a connection string pointing to the storage account. However, I would like the web job to query the Azure database and not work with the repository.

Is this doable?

Thanks,

+4
azure azure-webjobs
source share
3 answers

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

You can access Azure SQL databases from a web job, as shown in this.

+1
source share

As Victor wrote, sdk events are triggered by blobs, queues, and tables.
A simple solution for your need: write a console application with the pollig approach. No sdk required. 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 } 
+2
source share

To create a web task, you do not need to use webjobs sdk, you can use several types of executable files (.exe, .cmd, .js, .php, .py, ...).

Try using this new visual studio add-in: http://visualstudiogallery.msdn.microsoft.com/f4824551-2660-4afa-aba1-1fcc1673c3d0 , follow the instructions that you can link between your web application and the console application that will be published on the web Azure website on the website.

0
source share

All Articles