简体   繁体   English

SQL 来自.Net 5 Windows 服务的登录问题,但不是来自通过 Wix 安装程序安装的控制台

[英]SQL Login issue from .Net 5 Windows service but not from console installed via Wix installer

I have a.Net 5 Windows service (WindowsBackgroundService) that connects to a local SQL Express database instance.我有一个连接到本地 SQL Express 数据库实例的 .Net 5 Windows 服务 (WindowsBackgroundService)。 This database instance and application are meant to run on the local system, so I was trying to do Windows Authentication for SQL and not set up a login.此数据库实例和应用程序旨在在本地系统上运行,因此我尝试对 SQL 进行 Windows 身份验证,但未设置登录。

The service is also installed using the Wix 3.11 installer.该服务还使用 Wix 3.11 安装程序安装。 The service installs just fine and completes (it is also listed in my services and add/remove programs) but the service will not start.该服务安装正常并完成(它也在我的服务和添加/删除程序中列出)但该服务不会启动。 In the Event Viewer logs, this is what it says:在事件查看器日志中,它是这样写的:

Login failed for user 'NT AUTHORITY\SYSTEM'.用户“NT AUTHORITY\SYSTEM”登录失败。 Reason: Failed to open the explicitly specified database 'MyDatabase'.原因:无法打开明确指定的数据库“MyDatabase”。 [CLIENT: ] [客户: ]

Now, I understand that error points to a login issue in general but what I am confused by is I am using Windows Authentication as I mentioned but even more confusing, when I run the executable in the installed folder, it runs fine and connects to my SQL database.现在,我知道错误通常指向登录问题,但令我感到困惑的是我正在使用我提到的 Windows 身份验证,但更令人困惑的是,当我在安装的文件夹中运行可执行文件时,它运行良好并连接到我的SQL 数据库。

I guess this points to the permissions of the service as Wix installed it and those permissions are not good enough to satisfy Windows Auth for SQL?我猜这指向服务的权限,因为 Wix 安装了它,这些权限不足以满足 Windows 对 SQL 的授权?

So, I guess the question is, how do I configure Wix to install the service (hopefully without requiring the user to supply credentials during the installation) so that it can access SQL Express using Windows Auth?所以,我想问题是,我如何配置 Wix 来安装服务(希望不需要用户在安装过程中提供凭据)以便它可以使用 Windows Auth 访问 SQL Express? Here is how the service looks after it is installed:以下是该服务在安装后的样子:

服务登录

And here is the pertinent section of the Wix.wxs config:这是 Wix.wxs 配置的相关部分:

          <ServiceInstall
            Id="ServiceInstaller"
            Type="ownProcess"
            Name="MyService"
            Vital="yes"
            DisplayName="My Test Service"
            Description="My Test Service"
            Start="auto"
            ErrorControl="normal"
            Account="LocalSystem"
            Interactive="no" >
            <util:ServiceConfig
              FirstFailureActionType="restart"
              SecondFailureActionType="restart"
              ThirdFailureActionType="restart"
              ResetPeriodInDays="1"
              RestartServiceDelayInSeconds="30" />
            <util:PermissionEx 
              User="Everyone" 
              ServicePauseContinue="yes" 
              ServiceQueryStatus="yes" 
              ServiceStart="yes" 
              ServiceStop="yes" 
              ServiceUserDefinedControl="yes" />
          </ServiceInstall>
            <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="MyService" Wait="yes" />

Thanks!!谢谢!!

After doing more and more digging (ie: different ways of searching the same issue) I found this SO post:在进行越来越多的挖掘(即:搜索同一问题的不同方式)后,我发现了这篇 SO 帖子:

Add login to SQL 添加登录SQL

And it fixed my issue.它解决了我的问题。 The service now runs.该服务现在运行。

Problem solved!问题解决了!

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

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