Skip to content

Commit

Permalink
Change SqlConnection type
Browse files Browse the repository at this point in the history
  • Loading branch information
jrunestone authored and nul800sebastiaan committed Nov 2, 2022
1 parent eb1ae8c commit 30cebe2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Cultiv.Hangfire/HangfireComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
{
Expand All @@ -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),
Expand All @@ -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)
Expand Down

0 comments on commit 30cebe2

Please sign in to comment.