首页 > 解决方案 > 如何在 ASP.NET CORE Web API 中配置 Hangfire 以使用 postgresql 作为存储数据库?

问题描述

我同事的开发人员,我目前正在asp.net Core和Hangfire中开发一个Web API来执行一些后台作业处理,但我打算使用Postgresql作为我的数据存储。但是我的 WEB API 未能自动创建数据库对象,以便我可以使用 Hangfire。我需要你的帮助,提前谢谢。

**An unhandled exception occurred while processing the request.**

PostgresException: 42P01: relation "hangfire.counter" does not exist
Npgsql.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|194_0(NpgsqlConnector connector, bool async, DataRowLoadingMode dataRowLoadingMode, bool readingNotifications, bool isReadingPrependedMessage)
Npgsql.NpgsqlDataReader.NextResult(bool async, bool isConsuming, CancellationToken cancellationToken)
Npgsql.NpgsqlDataReader.NextResult()
Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, bool async, CancellationToken cancellationToken)
Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, bool async, CancellationToken cancellationToken)
System.Threading.Tasks.ValueTask<TResult>.get_Result()
System.Runtime.CompilerServices.ValueTaskAwaiter<TResult>.GetResult()
Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior)
Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
Dapper.SqlMapper.ExecuteReaderWithFlagsFallback(IDbCommand cmd, bool wasClosed, CommandBehavior behavior) in SqlMapper.cs
Dapper.SqlMapper.QueryImpl<T>(IDbConnection cnn, CommandDefinition command, Type effectiveType)+MoveNext() in SqlMapper.cs
System.Collections.Generic.List<T>..ctor(IEnumerable<T> collection)
System.Linq.Enumerable.ToList<TSource>(IEnumerable<TSource> source)
Dapper.SqlMapper.Query<T>(IDbConnection cnn, string sql, object param, IDbTransaction transaction, bool buffered, Nullable<int> commandTimeout, Nullable<CommandType> commandType) in SqlMapper.cs
Dapper.SqlMapper.Query(IDbConnection cnn, string sql, object param, IDbTransaction transaction, bool buffered, Nullable<int> commandTimeout, Nullable<CommandType> commandType) in SqlMapper.cs
Hangfire.PostgreSql.PostgreSqlMonitoringApi+<>c__DisplayClass28_0.<GetTimelineStats>b__0(IDbConnection connection)
Hangfire.PostgreSql.PostgreSqlStorage.UseConnection<T>(Func<IDbConnection, T> func)
Hangfire.PostgreSql.PostgreSqlMonitoringApi.GetTimelineStats(IDictionary<string, DateTime> keyMaps)
Hangfire.PostgreSql.PostgreSqlMonitoringApi.GetHourlyTimelineStats(string type)
Hangfire.PostgreSql.PostgreSqlMonitoringApi.HourlySucceededJobs()
Hangfire.Dashboard.Pages.HomePage.Execute()
Hangfire.Dashboard.RazorPage.TransformText(string body)
Hangfire.Dashboard.RazorPage.ToString()
Hangfire.Dashboard.RazorPageDispatcher.Dispatch(DashboardContext context)
Hangfire.Dashboard.AspNetCoreDashboardMiddleware.Invoke(HttpContext httpContext)
Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)`enter code here`
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

标签: hangfire

解决方案


推荐阅读