我遵循的教程-https://docs.hangfire.io/en/latest/getting-started/aspnet-core-applications.html
在启动类中配置服务
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IBackgroundJobClient backgroundJobs)
{
app.UseHangfireDashboard();
backgroundJobs.Enqueue(() => Console.WriteLine("Hello world from Hangfire!"));
}
SqlException:无法打开数据库"HangfireTest";登录时请求。登录失败。用户"PENGUIN\PC"登录失败。
运行应用程序时出现此异常?
我可以通过更改apsettings.json文件中的连接字符串来解决这个问题,如果需要查找连接字符串,请右键单击visual studio的SQl服务器对象资源管理器的数据库实例->属性并获取连接字符串。此连接字符串应与一起放置appsettings.json
"ConnectionStrings": {
"ApplicationDbContext": "server=(localdb)\mssqllocaldb;Database=ApplicationDbContext;Trusted_Connection=True;MultipleActiveResultSets=true",
"HangfireConnection": "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"