Azure的Web作业 - 如何连接到Azure的MS SQL数据库? [英] Azure Web Job - How to connect to an Azure MS SQL Database?

查看:294
本文介绍了Azure的Web作业 - 如何连接到Azure的MS SQL数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC网站,发布到Azure的地方使用了Azure的SQL数据库。

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

现在是时候了,我们需要运行计划任务发送短信提醒。我是IM pression了Azure的网上工作是一个很好的适合这种下但我有一些问题得到它运行起来。

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.

我添加了一个控制台应用程序到我的网站的解决方案,并通过从控制台应用程序(我想发布为Web作业)EF数据模型引用。

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:

更多信息:用户帐户连接字符串缺失。这可以通过AzureJobsData连接字符串或通过构造函数来设置。

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

这表明,网络招聘是专门找一个指向存储帐户的连接字符串。不过,我想在网上工作来查询Azure数据库,而不是存储工作。

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.

这是可行的?

谢谢,

推荐答案

不幸的是,WebJobs SDK不支持SQL数据库的作为触发器的。对于触发器,它仅支持Azure存储(斑点,队列和表)。

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

您可以访问网络工作的Azure SQL数据库正如本回答

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

这篇关于Azure的Web作业 - 如何连接到Azure的MS SQL数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆