Reputation: 649
I've written a Windows Service in C# using HangFire. Service1 looks like :
public Service1()
{
InitializeComponent();
GlobalConfiguration.Configuration.UseSqlServerStorage(@"Data Source=DESKTOP-B90D804\SQLEXPRESS;Initial Catalog=Leavingstone_Geocell_Students;Integrated Security=True");
}
protected override void OnStart(string[] args)
{
File.Create(AppDomain.CurrentDomain.BaseDirectory + "OnStart5.txt");
_server = new BackgroundJobServer();
}
protected override void OnStop()
{
File.Create(AppDomain.CurrentDomain.BaseDirectory + "OnStop5.txt");
_server.Dispose();
}
But I keep getting Error 1053 from windows service when I try to install. saying that the service did not respond to the start or control reuqest in a timely fashion.
But If I take Out "GlobalConfiguration.Configuration.UseSqlServerStorage(@"Data Source=DESKTOP-B90D804\SQLEXPRESS;Initial Catalog=Leavingstone_Geocell_Students;Integrated Security=True");
" it works.
Also when I run it into a debug mode from visual studio it also works without taking out GlobalConfiguration section. Windows service uses Local system account.
Upvotes: 1
Views: 402
Reputation: 649
I've granted sql permission to NT AUTHORITY\SYSTEM user and problem solved.
Upvotes: 1