简体   繁体   中英

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.

[2015-12-03 13:56:06] [ERROR] [] [Error occurred during execution of 'Server Bootstrapper' component. 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".

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.

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.

Also, in the IIS server, we already set the Identity to "ApplicationPoolIdentity" for the application pools. 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.

If you are using EF Code First, your database isn't created until the context is created and accessed for the first time.

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.

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.
  3. The web application start finishes since the hangfire service crashing isn't fatal to the application.
  4. Something in your web app calls into EntityFramework.
  5. EF runs and creates the database (likely no hangfire tables at this point)
  6. you access the hangfire dashboard, hangfire is now able to connect, and see the tables don't exist, so it creates them. (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.

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.

Also, (and this probably isn't it), GlobalConfiguration.Configuration.UseSqlServerStorage() should run first before other Hangfire startup configuration.

Hope that helps!

Steve

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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