I installed the hangfire with Nuget.
PM> Install-Package Hangfire
Then updated the OWIN Startup class with the following lines:
public void Configuration(IAppBuilder app)
{
GlobalConfiguration.Configuration.UseSqlServerStorage("MySqlConnection");
app.UseHangfireDashboard();
app.UseHangfireServer();
}
I named the connection string name on the web.config as the name of the connectionString In UseSqlServerStorage.
web.config:
<connectionStrings>
<add name="MyEntities" connectionString="metadata=res://*/CRMModelContext.csdl|res://*/CRMModelContext.ssdl|res://*/CRMModelContext.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=xxx;persist security info=True;user id=sa;password=123;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="MySqlConnection" connectionString="User ID=sa;Initial Catalog=xxx;Password=123;Integrated Security=False;Data Source=." />
SQL Server 2008 R2 is installed on the system but The database for the hangfire is not in it.
Finally, when I run the program, the error below.
My Job:
BackgroundJob.Enqueue<Receiver>(x=>x.EmailReceiving());
RecurringJob.AddOrUpdate<Receiver>(x => x.EmailReceiving(), Cron.MinuteInterval(15));
error:
JobStorage.Current property value has not been initialized. You must set it before using Hangfire Client or Server API.
GlobalConfiguration.Configuration.UseSqlServerStorage("MySqlConnection");
is using MySqlConnection
as a connection string, not the value of MySqlConnection
!
Are you using MsSql Server or MySql Server?
Try :
GlobalConfiguration.Configuration.UseSqlServerStorage(ConfigurationManager.ConnectionStrings["MySqlConnection"].ConnectionString);