如何解决“连接字符串格式不正确”?

问题描述:

我想创建一些Azure函数。我开始通过教程here。问题是,当我尝试在本地进行调试时,我不断收到错误。如何解决“连接字符串格式不正确”?

这里是我的local.settings.json

{ 
    "IsEncrypted": false, 
    "Values": { 
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=XYZ;AccountKey=<removed>;BlobEndpoint=https://XXX.blob.core.windows.net/;QueueEndpoint=https://XXX.queue.core.windows.net/;TableEndpoint=https://XXX.table.core.windows.net/;FileEndpoint=https://XXX.file.core.windows.net/;", 
    "AzureWebJobsDashboard": "", 
    "QueueStorage": "https://XXX.queue.core.windows.net/myqueue-items" 
    } 
} 

下面是代码(包括对Azure的功能实际上只是模板代码)

using System; 
using Microsoft.Azure.WebJobs; 
using Microsoft.Azure.WebJobs.Host; 

namespace FunctionApp3 
{ 
    public static class SampleFunction 
    { 
     [FunctionName("SampleFunction")] 
     public static void Run([QueueTrigger("myqueue-items", Connection = "QueueStorage")]string myQueueItem, TraceWriter log) 
     { 
      log.Info($"C# Queue trigger function processed: {myQueueItem}"); 
     } 
    } 
} 

这里是输出到本地控制台窗口:

[8/29/2017 5:53:01 PM] Microsoft.Azure.WebJobs.Host: Error indexing method 'SampleFunction.Run'. Microsoft.Azure.WebJobs.Host: Failed to validate Microsoft Azure WebJobs SDK QueueStorage connection string. The Microsoft Azure Storage account connection string is not formatted correctly. Please visit https://go.microsoft.com/fwlink/?linkid=841340 for details about configuring Microsoft Azure Storage connection strings. 
[8/29/2017 5:53:01 PM] Error indexing method 'SampleFunction.Run' 
[8/29/2017 5:53:01 PM] Microsoft.Azure.WebJobs.Host: Error indexing method 'SampleFunction.Run'. Microsoft.Azure.WebJobs.Host: Failed to validate Microsoft Azure WebJobs SDK QueueStorage connection string. The Microsoft Azure Storage account connection string is not formatted correctly. Please visit https://go.microsoft.com/fwlink/?linkid=841340 for details about configuring Microsoft Azure Storage connection strings. 

我试着重写连接字符串几次,但似乎无法得到r错误的ID。我查阅了信息here,但仍无法使其工作。

我缺少什么?

+0

您是否尝试过在每个网址结束后删除斜线?目前你有“core.windows.net/;”但你应该有“core.windows.net”。它有帮助吗? – DotNetMatt

它看起来像预计在设置中存在完整的存储连接字符串,而不仅仅是队列的URL。

喜欢的东西:

{ 
    "IsEncrypted": false, 
    "Values": { 
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=XYZ;AccountKey=<removed>;BlobEndpoint=https://XXX.blob.core.windows.net/;QueueEndpoint=https://XXX.queue.core.windows.net/;TableEndpoint=https://XXX.table.core.windows.net/;FileEndpoint=https://XXX.file.core.windows.net/;", 
    "AzureWebJobsDashboard": "", 
    "QueueStorage": "DefaultEndpointsProtocol=https;AccountName=XYZ;AccountKey=<removed>;BlobEndpoint=https://XXX.blob.core.windows.net/;QueueEndpoint=https://XXX.queue.core.windows.net/;TableEndpoint=https://XXX.table.core.windows.net/;FileEndpoint=https://XXX.file.core.windows.net/;" 
    } 
} 

正如juunas说,我们需要Connection应用程序设置完整的连接字符串。

如果此连接是AzureWebJobsStorage的副本,您可以简单地将您的属性更改为[QueueTrigger("my-queue-items")](如果没有指定其他连接,则为AzureWebJobsStorage为默认值)。