From 30cebe2899d9fc5ac98517739acf1c54e49075d3 Mon Sep 17 00:00:00 2001 From: Johan Runsten Date: Wed, 2 Nov 2022 14:54:42 +0100 Subject: [PATCH] Change SqlConnection type --- Cultiv.Hangfire/HangfireComposer.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Cultiv.Hangfire/HangfireComposer.cs b/Cultiv.Hangfire/HangfireComposer.cs index 4bf6bb1..3056be7 100644 --- a/Cultiv.Hangfire/HangfireComposer.cs +++ b/Cultiv.Hangfire/HangfireComposer.cs @@ -25,6 +25,10 @@ public void Compose(IUmbracoBuilder builder) return; } + // Explicitly use the SqlConnection in the Microsoft.Data namespace to support extended connection string parameters such as "authentication" + // https://github.com/HangfireIO/Hangfire/issues/1827 + var dbConnFunc = () => new Microsoft.Data.SqlClient.SqlConnection(connectionString); + // Configure Hangfire to use our current database and add the option to write console messages builder.Services.AddHangfire(configuration => { @@ -33,7 +37,7 @@ public void Compose(IUmbracoBuilder builder) .UseSimpleAssemblyNameTypeSerializer() .UseRecommendedSerializerSettings() .UseConsole() - .UseSqlServerStorage(connectionString, new SqlServerStorageOptions + .UseSqlServerStorage(dbConnFunc, new SqlServerStorageOptions { CommandBatchMaxTimeout = TimeSpan.FromMinutes(5), SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5), @@ -50,7 +54,7 @@ public void Compose(IUmbracoBuilder builder) // For some reason we need to give it the connection string again, else we get this error: // https://discuss.hangfire.io/t/jobstorage-current-property-value-has-not-been-initialized/884 - JobStorage.Current = new SqlServerStorage(connectionString); + JobStorage.Current = new SqlServerStorage(dbConnFunc); } private static void AddAuthorizedUmbracoDashboard(IUmbracoBuilder builder)