由于找不到连接字符串,无法启动azure WebJob

时间:2018-03-19 15:18:05

标签: azure azure-storage azure-webjobs

我是Azure WebJobs的新手。我试图在晚上11点每天运行某种方法:

以下是我的代码:

public class Functions
{
    // This function will get triggered/executed when a new message is written 
    // on an Azure Queue called queue.
    public static void ProcessQueueMessage([QueueTrigger("queue")] string message, TextWriter log)
    {
        log.WriteLine(message);
    }

    public static void DailyReport([TimerTrigger("0 0 23 * * *")] TimerInfo timer, TextWriter log)
    {
        log.WriteLine("DailyReport was triggered!");
    }
}

但是,我在启动时不断收到InvalidOperationException:

An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll Microsoft Azure WebJobs SDK 'Dashboard' connection string is missing or empty. The Microsoft Azure Storage account connection string can be set in the following ways: 1. Set the connection string named 'AzureWebJobsDashboard' in the connectionStrings section of the .config file in the following format <add name="AzureWebJobsDashboard" connectionString="DefaultEndpointsProtocol=http|https;AccountName=NAME;AccountKey=KEY" />, or 2. Set the environment variable named 'AzureWebJobsDashboard', or 3. Set corresponding property of JobHostConfiguration.

现在,我一直在努力争取这一天。我尝试过的事情:

  • 在“连接字符串”下的“应用程序设置”窗格中配置AzureWebJobsDashboardAzureWebJobsStorage。以前,我在我的App.config中有这些,但一直收到错误。这似乎让我超越了Azure上的错误:我现在在Azure WebJobs日志中看到了一个不同的例外:

Unhandled Exception: Newtonsoft.Json.JsonException: Error creating 'Microsoft.Azure.WebJobs.Host.Protocols.PersistentQueueMessage+PersistentQueueMessageConverter'. ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

我也不知道该怎么做。 但是,在尝试本地运行时,我仍然会收到抱怨连接字符串的InvalidOperationException。

  • 在本地测试的地方读取,我应该设置一个名为AzureWebJobsEnv的环境变量,其值为Development。这样做了,但config.IsDevelopment仍然返回false。不知道那是什么。
  • 从头开始创建一个Azure Web Jobs项目并更新了所有NuGet包(这需要两次通过)。
  • 验证我安装了Azure存储模拟器,并尝试了模拟器连接字符串。我的app.config现在包含:

    <configuration>
      <appSettings>
        <add key="StorageConnectionString" value="UseDevelopmentStorage=true" />
      </appSettings>
      <connectionStrings>
        <!-- The format of the connection string is     "DefaultEndpointsProtocol=https;AccountName=NAME;AccountKey=KEY" -->
        <!-- For local execution, the value can be set either in this config     file or through environment variables -->
        <add name="AzureWebJobsDashboard"     connectionString="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;" />
        <add name="AzureWebJobsStorage"     connectionString="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;" />
      </connectionStrings>
    

没有运气:在启动时仍然会因同样的错误而崩溃。

这是我的Program.cs:

static void Main()
    {
        var config = new JobHostConfiguration();
        config.UseTimers();
        config.Queues.MaxDequeueCount = 2;
        config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(4);
        config.Queues.BatchSize = 2;

        if (config.IsDevelopment) {
            config.UseDevelopmentSettings();
        }

        var host = new JobHost(config);
        // The following code ensures that the WebJob will be running continuously
        host.RunAndBlock();
        //host.Start();
    }

非常感谢任何帮助!

0 个答案:

没有答案