Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsAzureSBConnection' is missing or empty

I created an Azure Function App in Visual Studio 2015. The App has a trigger for service bus queues. The app works perfectly when I run it locally. It is able to read the data from the Service Bus queue (configured via a variable named AzureSBConnection) and log it in my database.

But it gives me the following error when deployed in Azure:

Function ($ServiceBusQueueTriggerFunction) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.ServiceBusQueueTriggerFunction'. Microsoft.Azure.WebJobs.ServiceBus: Microsoft Azure WebJobs SDK ServiceBus connection string 'AzureWebJobsAzureSBConnection' is missing or empty.

Note that my connection is called AzureSBConnection and not AzureWebJobsAzureSBConnection. Also, the connection works locally. And finally, the deployed file looks exactly like the local file.

The Visual Studio structure looks like the following:

Visual Studio Structure

The function.json file has a bunch of settings as shown below:

FUnction.json

Then in the Appsettings.json file, I have the following:

App Settings

For deploying, I FTPed the files to the D:\home\site\wwwroot location for my Function App in Azure. The final structure in Kudu looks like:

wwwroot

And if I go inside my function folder:

enter image description here

Here is the deployed function.json:

Deployed Function.json

And here is the deployed appsettings:

Deployed app settings

The deployed json files are exactly the same as the local files. But the deployed version is erroring out because of the missing AzureWebJobsAzureSBConnection. What am I doing wrong?

like image 647
Yasir Avatar asked Mar 23 '17 23:03

Yasir


1 Answers

Only environment variables are supported for app settings and connection strings.

You need to make sure that the environment variable AzureWebJobsAzureSBConnection is set on your Function's app settings in the portal:

function app

and then once there, you need to add the AzureWebJobsAzureSBConnection variable with the proper connection string:

enter image description here

and then you can access this via code by:

Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);

This will obtain the value from either the appsettings.json or the environment variable depending on where the function is being executed from, (local debugging or deployed on Azure)

like image 50
flyte Avatar answered Oct 02 '22 22:10

flyte