Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 5 使用Hangfire时获取SQL Server错误_Asp.net Mvc 5_Hangfire - Fatal编程技术网

Asp.net mvc 5 使用Hangfire时获取SQL Server错误

Asp.net mvc 5 使用Hangfire时获取SQL Server错误,asp.net-mvc-5,hangfire,Asp.net Mvc 5,Hangfire,我正在ASP.NET MVC5应用程序中使用Hangfire发送电子邮件。到目前为止,它工作正常,但现在当我运行应用程序时,它抛出以下错误: 数据库中已存在名为“作业”的对象。正在调用Hangfire SQL对象。。。数据库架构[HangFire]已存在表[HangFire]。[schema]已存在。。安装架构版本1 从这个错误中,我了解到Hangfire试图在数据库中创建所有已经存在的表。但我并没有得到它背后的原因,因为到目前为止,应用程序运行得很好,即使我在本地多次运行它。这发生在我身上,因

我正在ASP.NET MVC5应用程序中使用Hangfire发送电子邮件。到目前为止,它工作正常,但现在当我运行应用程序时,它抛出以下错误:

数据库中已存在名为“作业”的对象。正在调用Hangfire SQL对象。。。数据库架构[HangFire]已存在表[HangFire]。[schema]已存在。。安装架构版本1


从这个错误中,我了解到Hangfire试图在数据库中创建所有已经存在的表。但我并没有得到它背后的原因,因为到目前为止,应用程序运行得很好,即使我在本地多次运行它。

这发生在我身上,因为sql数据库用户在数据库中没有适当的权限(
db\u datareader
db\u ddladmin
db\u datawriter
,等等)


添加适当的权限会立即解决问题。

这发生在我身上,我运行此查询并重新启动服务器。 只需运行查询:

INSERT INTO [HangFire].[Schema]
           ([Version])
     VALUES
           (5)

在通过.bacpac导出\导入数据库后,我遇到了这个问题,但出现了错误。我删除了开发数据库上的所有hangfire表,它工作正常(小心,不要在生产数据库上这样做)


Asp Core 2.2中的以下代码解决了我的问题:

启动类-->配置服务方法:

appsetting.json文件:


这可能是一个bug,您可以通过使用以下变量禁用创建表的过程:options=new SqlServerStorageOptions{prepareschemaifrequired=false};GlobalConfiguration.Configuration.UseSqlServerStorage(“,选项);这是一个非常恼人的错误,hangfire试图在应用程序重新启动后重新创建自己,即使它已经被创建。在执行新部署时,上面建议的修复程序不起作用
DROP TABLE IF EXISTS HangFire.AggregatedCounter
DROP TABLE IF EXISTS HangFire.Counter
DROP TABLE IF EXISTS HangFire.Hash
DROP TABLE IF EXISTS HangFire.JobParameter
DROP TABLE IF EXISTS HangFire.JobQueue
DROP TABLE IF EXISTS HangFire.List
DROP TABLE IF EXISTS HangFire.[Schema]
DROP TABLE IF EXISTS HangFire.Server
DROP TABLE IF EXISTS HangFire.[Set]
DROP Table IF EXISTS HangFire.State
DROP TABLE IF EXISTS HangFire.Job
  var cfg = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json")
            .Build();

        services.AddHangfire(x => x
            .UseSqlServerStorage(
                cfg.GetConnectionString("DefaultConnection"),
                new SqlServerStorageOptions
                {
                    PrepareSchemaIfNecessary = false
                }
            ));
 "ConnectionStrings": {
    "DefaultConnection": "Data Source=.;Initial Catalog=databaseName;Persist Security Info=True;User ID=sa;Password=123;MultipleActiveResultSets=True;Application Name=Hang-fire"
  },