Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'nameOrConnectionString')

1.5k views Asked by At

I am using hangfire in my ASP.net core application to run some background task. I am using IIS and i have configured Hangfire as follows:

using Hangfire;

namespace Whm.APIPortal
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHangfire(option =>
            {
                option.UseSqlServerStorage(Configuration.GetConnectionString("HangFireConnection"));
            });
            services.AddHangfireServer();
         }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.UseHangfireDashboard();

            app.UseHangfireServer();
         }
     }
}

Below is my appsettings.json file

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "ConnectionStrings": {
    "DefaultConnection": "Server=.\\SQLEXPRESS;Database=Whm;User Id=sa;Password=***;MultipleActiveResultSets=true",
    "HangFireConnection": "Server=.\\SQLEXPRESS;Database=WhmHangFire;User Id=sa;Password=***;"
  },
  "AllowedHosts": "*"
}

Whenever I try to launch the application I get below exception

Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'nameOrConnectionString')

I have created the database "WhmHangFire" on my sql server.

Still I get same exception. could somebody explain what is causing this issue?

Thanks

0

There are 0 answers