简体   繁体   English

没有活动的服务器。 后台任务将不被处理

[英]There are no active servers. Background tasks will not be processed

I have a problem which I already looking at it for a few days and still have no solution. 我有一个问题,已经几天了,但仍然没有解决方案。

I found this exception in my C# web app log. 我在C#Web应用程序日志中发现了此异常。

[2015-12-03 13:56:06] [ERROR] [] [Error occurred during execution of 'Server Bootstrapper' component. [2015-12-03 13:56:06] [错误] [] [执行“服务器引导程序”组件时发生错误。 Execution will be retried (attempt 120 of 2147483647) in 00:05:00 seconds.] [System.Data.SqlClient.SqlException (0x80131904): Login failed for user "A Network account". 将在00:05:00秒内重试执行(尝试2147483647的120)。] [System.Data.SqlClient.SqlException(0x80131904):用户“ A网络帐户”的登录失败。

It appears to me that it is using the network account to access the SQL database and because that network account is not granted access to the database, hence login failed and server cannot startup. 在我看来,它正在使用网络帐户访问SQL数据库,并且因为未授予该网络帐户访问数据库的权限,因此登录失败并且服务器无法启动。

However, when I go to the Hangfire dashboard, I can see the recurring jobs, which seems to me that hangfire can access the database with the right account for retrieving the recurring jobs. 但是,当我转到Hangfire仪表板时,可以看到重复的作业,在我看来,hangfire可以使用正确的帐户访问数据库以检索重复的作业。

Also, in the IIS server, we already set the Identity to "ApplicationPoolIdentity" for the application pools. 另外,在IIS服务器中,我们已经将应用程序池的标识设置为“ ApplicationPoolIdentity”。 Hence, we should use the virtual account instead of the network account. 因此,我们应该使用虚拟帐户而不是网络帐户。

May I know anyone has the similar problem and have the solution. 我是否可以知道有人遇到类似的问题并找到解决方案。 Really appreciate for your help!! 非常感谢您的帮助!

I ran into the same issue using Hangfire with SQL Server and EntityFramework Code First where EntityFramework was responsible for creating the database, so this suggestion is based purely off of that scenario. 我在将Hangfire与SQL Server和EntityFramework Code First结合使用时遇到了相同的问题,其中EntityFramework负责创建数据库,因此,该建议完全基于这种情况。

If you are using EF Code First, your database isn't created until the context is created and accessed for the first time. 如果您使用的是EF Code First,则直到第一次创建并访问上下文后,才会创建数据库。

This means that at App Start your database might not exist. 这意味着在“应用程序启动”中,您的数据库可能不存在。 Hangfire won't create the database, it only creates the tables in an already existing database. Hangfire不会创建数据库,它只会在现有数据库中创建表。

So what you might be seeing is: 因此,您可能会看到的是:

  1. No database exists. 不存在数据库。
  2. Your app start's up and Hangfire tries to get itself running, the server process throws an error because EF hasn't created the DB. 您的应用程序启动,并且Hangfire尝试使其运行,由于EF尚未创建数据库,服务器进程将引发错误。
  3. The web application start finishes since the hangfire service crashing isn't fatal to the application. 由于hangfire服务崩溃对应用程序来说不是致命的,因此Web应用程序启动完成。
  4. Something in your web app calls into EntityFramework. Web应用程序中的某些内容会调用EntityFramework。
  5. EF runs and creates the database (likely no hangfire tables at this point) EF运行并创建数据库(目前可能没有hangfire表)
  6. you access the hangfire dashboard, hangfire is now able to connect, and see the tables don't exist, so it creates them. 您访问hangfire仪表板后,hangfire现在可以连接,并且看到表不存在,因此可以创建它们。 (now you will see the tables in your db) (现在您将在数据库中看到表)
  7. The dashboard can now see the database and show you the stats (likely 0 servers running) so it seems like everything is working. 仪表板现在可以查看数据库并向您显示统计信息(可能有0台服务器正在运行),因此看起来一切正常。

The way I solved it was to make sure that even if the database is empty (not tables), it is at least created. 我解决问题的方法是确保即使数据库为空(不是表),也至少要创建它。 This was hangfire can access it to install it's tables and start, and EF can access it, and create it's schema. hangfire可以访问它以安装它的表并启动,而EF可以访问它并创建它的模式。

Also, (and this probably isn't it), GlobalConfiguration.Configuration.UseSqlServerStorage() should run first before other Hangfire startup configuration. 另外,(也许不是),GlobalConfiguration.Configuration.UseSqlServerStorage()应该在其他Hangfire启动配置之前先运行。

Hope that helps! 希望有帮助!

Steve 史蒂夫

您应该创建后台作业服务器实例,请参见此处的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM