18
votes

I'm trying to work with Azure Webjobs, I understand the way its works but I don't understand why I need to use two connection strings, one is for the queue for holding the messages but

  1. why there is another one called "AzureWebJobsDashboard" ?

  2. What its purpose?

  3. And where I get this connection string from ?

At the moment I have one Web App and one Webjob at the same solution, I'm experiment only locally ( without publishing anything ), the one thing I got up in the cloud is the Storage account that holds the queue.

I even try to put the same connection string in both places ( AzureWebJobsDashboard,AzureWebJobsStorage) but its throw exception : "Cannot bind parameter 'log' when using this trigger."

Thank you.

3
Can you debug Azure webjobs locally without azure storage account ?ManirajSS
@ManirajSS In the Solution Explorer -> right click on the WebJob project and select Debug -> Start new instance. Let me know if it works for you.Ron
I am able to debug the webjobs by clicking set as startup project and run. But im having issue with connection string.i dont have storage account and not able to find how to configure localdb for webjobs.ManirajSS
@ManirajSS The connection string is need to be a connection string of Storage Account. You dont need DB you need Storage Account. I dont know if you could setup Storage Account locally, search for it. If you need anything else.. im here :)Ron

3 Answers

18
votes

There are two connection strings because the WebJobs SDK writes some logs in the storage account. It gives you the possibility of having one storage account just for data (AzureWebJobsStorage) and the another one for logs (AzureWebJobsDashboard). They can be the same. Also, you need two of them because you can have multiple job hosts using different data accounts but sending logs to the same dashboard.

The error you are getting is not related to the connection strings but to one of the functions in your code. One of them has a log parameter that is not of the right type. Can you share the code?

15
votes

Okay, anyone coming here looking for an actual answer of "where do I get the ConnectionString from"... here you go.

On the new Azure portal, you should have a Storage Account resource; mine starts with "portalvhds" followed by a bunch of alphanumerics. Click that so see a resource Dashboard on the right, followed immediately by a Settings window. Look for the Keys submenu under General -- click that. The whole connection string is there (actually there are two, Primary and Secondary; I don't currently understand the difference, but let's go with Primary, shall we?).

Copy and paste that in your App.config file on the connectionString attribute of the AzureWebJobsDashboard and AzureWebJobsStorage items. This presumes for your environment you only have one Storage Account, and so you want that same storage to be used for data and logs.

I tried this, and at least the WebJob ran without throwing an error.

1
votes

@RayHAz - Expanding upon your above answer (thanks)...

I tried this https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-get-started

but in .Net Core 2.1, was getting exceptions about how it couldn't find the connection string.

Long story short, I ended up with the following, which worked for me:

appsettings.json, in a .Net Core 2.1 Console app:

{
  "ConnectionStrings": {
  "AzureWebJobsStorage": "---your Azure storage connection string here---",
  "AzureWebJobsDashboard":"---the same connectionstring---"
  }
}

... and my Program.cs file...

using System;
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace YourWebJobConsoleAppProjectNamespaceHere
{
    public class Program
    {
        public static IConfiguration Configuration;
        static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(Path.Combine(AppContext.BaseDirectory))
                .AddJsonFile("appsettings.json", true);
            Configuration = builder.Build();

            var azureWebJobsStorageConnectionString = Configuration.GetConnectionString("AzureWebJobsStorage");
            var azureWebJobsDashboardConnectionString = Configuration.GetConnectionString("AzureWebJobsDashboard");

            var config = new JobHostConfiguration
            {
                DashboardConnectionString = azureWebJobsDashboardConnectionString,
                StorageConnectionString = azureWebJobsStorageConnectionString
            };

            var loggerFactory = new LoggerFactory();
            config.LoggerFactory = loggerFactory.AddConsole();

            var host = new JobHost(config);
            host.RunAndBlock();
        }
    }
}