Hangfire: Using SQLServerStorage in NET.Core with Active Directory Password authentication throws keyword not supported

Created on 10 Mar 2021  路  3Comments  路  Source: HangfireIO/Hangfire

Version info:
.NET Core Version 3.1
Hangfire Version 1.7.19

Connection string example (using Active Directory Password authentication, Azure SQL Database):

Data Source=AZURE_DATA_SOURCE;Initial Catalog=DATABASE_NAME;Authentication=Active Directory Password;Persist Security Info=True;User id=USER@COMPANY;Password=**;

The same connection string in Hangifre 1.7.6 on NET Framework 4.8 works.
The same connection in EF Core 3.0.0 on .NET Core 3.1 is working.

I am missing something?

Attached image:
10-3-2021 13-13-06

Thanks.

Most helpful comment

Hey @fb5000 , with a little search and help from my work colleagues, the library that Hangfire uses to connect to SQL Server instance is System.Data.SqlClient, which doesnt suport Authentication with AD.

For that to work Hangfire must change the library they`re using. I tried to fork the repo and work in a solution my self, but this kind of thing is too dificult hahaha

Here`s an open issue where people request a support for Microsoft.Data.Client #https://github.com/HangfireIO/Hangfire/issues/1514

As a workaround, you can do this with following code:
GlobalConfiguration.Configuration
.UseSqlServerStorage(
() => new Microsoft.Data.SqlClient.SqlConnection(@"Server=.\;Database=Hangfire.Sample;Trusted_Connection=True;"));

All 3 comments

I'm having the same problem! I'm starting to think that Hangfire cant connect do Azure Dbs with Active Directory Authentication type.

Hey @fb5000 , with a little search and help from my work colleagues, the library that Hangfire uses to connect to SQL Server instance is System.Data.SqlClient, which doesnt suport Authentication with AD.

For that to work Hangfire must change the library they`re using. I tried to fork the repo and work in a solution my self, but this kind of thing is too dificult hahaha

Here`s an open issue where people request a support for Microsoft.Data.Client #https://github.com/HangfireIO/Hangfire/issues/1514

As a workaround, you can do this with following code:
GlobalConfiguration.Configuration
.UseSqlServerStorage(
() => new Microsoft.Data.SqlClient.SqlConnection(@"Server=.\;Database=Hangfire.Sample;Trusted_Connection=True;"));

Perfect! That's was what i was looking for, it's working now.
Obrigado!

Was this page helpful?
0 / 5 - 0 ratings