简体   繁体   English

C#Windows服务Hangfire错误:1053(GlobalConfiguration连接到数据库)

[英]C# Windows Service Hangfire Error : 1053(GlobalConfiguration connecting to database)

I've written a Windows Service in C# using HangFire. 我已经使用HangFire用C#编写了Windows服务。 Service1 looks like : Service1看起来像:

    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. 但是,当我尝试安装时,我一直从Windows服务获取错误1053。 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. 但是,如果我取出“ GlobalConfiguration.Configuration.UseSqlServerStorage(@"Data Source=DESKTOP-B90D804\\SQLEXPRESS;Initial Catalog=Leavingstone_Geocell_Students;Integrated Security=True"); “,它将起作用。

Also when I run it into a debug mode from visual studio it also works without taking out GlobalConfiguration section. 另外,当我从Visual Studio将其运行到调试模式时,它也可以正常工作,而无需删除GlobalConfiguration部分。 Windows service uses Local system account. Windows服务使用本地系统帐户。

我已向NT AUTHORITY \\ SYSTEM用户授予sql权限,问题已解决。

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

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