Hangfire with Azure SQL Active Directory in .net core 3.1

Tags: #<Tag:0x00007efd24328f48>

Hi,

I am trying to get following code working with Azure SQL Active Directry. As soon as I run code, it’s giving me " 500.33 ANCM Request Handler Load Failure error".

Following code taken from Using Hangfire with Azure and Managed Identity

services.AddHangfire(config =>
{
config.UseSqlServerStorage(sqlConn, new SqlServerStorageOptions
{
UseRecommendedIsolationLevel = true
});
});

static SqlConnection sqlConn()
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder.ConnectionString = “connectionString”;
SqlConnection conn = new SqlConnection(builder.ConnectionString);
conn.AccessToken = new Microsoft.Azure.Services.AppAuthentication.AzureServiceTokenProvider().GetAccessTokenAsync(“https://database.windows.net/”).Result;
return conn;
}

Code works fine without adding this code.

Please let help me with following question.

  1. Is hangfire can work with Azure SQL Active Directory.
  2. If yes, What am I doing wrong?
  3. Any suggestions.