Hangfire不会在IIS中创建表 [英] Hangfire doesn't create tables in IIS
问题描述
我已使用本指南 https://docs.hangfire.io/en/latest/getting-started/aspnet-core-applications.html .
当我删除我的MyProject_dev
MSSQL数据库并运行Update-Database
时,只会创建我的自定义表.运行项目后,将添加Hangfire表.
When I delete my MyProject_dev
MSSQL db and run Update-Database
only my custom tables are created. After I run the project, the Hangfire tables are added.
在appsettings.production.json
中,我已将数据库配置为MyProject_prod
,然后单击带有选中的 Entity Framework Migrations 的文件夹发布,以便构建过程可以创建<我需要将SQL应用于MyProject_prod
数据库的EFSQLScripts
文件夹中的em> .sql 文件.
In appsettings.production.json
I have configured the db to be MyProject_prod
and I click on Folder publish with checked Entity Framework Migrations so the build process can create a .sql file in the EFSQLScripts
folder with the SQL I need to apply to the MyProject_prod
database.
问题在于.sql文件仅包含我的自定义表.当我运行IIS站点时,与在本地使用 F5 运行项目时相比,没有在MyProject_prod
db中创建Hangfire表,如果没有,则在MyProject_dev
中创建它们存在.查看日志,我发现已建立到MyProject_prod
db的连接,错误是:
The problem is that the .sql file contains only my custom tables. When I run the IIS site the Hangfire tables aren't created in MyProject_prod
db, in comparison to when I run the project with F5 locally, where they are created in MyProject_dev
if they do not exists. Looking at the logs I see that the connection to the MyProject_prod
db is made, the error is:
[ERR] Execution BackgroundServerProcess is still in the Failed state for 00:20:45.1406056 due to an exception, will be retried no more than in 00:00:15
System.Data.SqlClient.SqlException (0x80131904): Invalid object name 'HangFire.Server'.
我可以从我的MyProject_dev
数据库中导出表,并将它们导入到MyProject_prod
数据库中,但是我认为这不是正确的方法.在IIS下运行应用程序时,为什么不创建表?
I could export the tables from my MyProject_dev
db and import them in the MyProject_prod
db, but I don't think this would be the right approach. Why aren't the tables created when the app is run under IIS?
推荐答案
尝试在生产中手动创建数据库,而不添加任何表.在您的配置中,将其指向新创建的数据库. hangfire bot可能具有建立数据库的权限.
Try creating the database manually in production, without adding any tables. In your config, point it at the newly created db. This may be an issue with hangfire bot having the permissions to build create the database.
这篇关于Hangfire不会在IIS中创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!