登录失败.用户“NT AUTHORITYSYSTEM"登录失败 [英] Login failed. Login failed for user 'NT AUTHORITYSYSTEM'
问题描述
我创建了一个 Windows 服务 &我的服务依赖于 SQL 服务器服务.首先,SQL启动,然后我的服务在启动PC或重新启动PC时启动.
I have created a windows service & my service is dependent on the SQL server service. First, SQL started and then my service started when starting PC or restarting PC.
这工作正常,但问题是 Windows 服务无法读取数据库文件,抛出异常无法打开用户默认数据库.登录失败.用户NT AUTHORITYSYSTEM"登录失败当我尝试读取数据库.
This works fine but the issue is database file can not be read by the Windows service, throwing the exception "Cannot open user default database. Login failed.Login failed for user 'NT AUTHORITYSYSTEM' " when i am trying to read the database.
如果我启动计算机 &登录然后它无法读取数据库,但如果我已经启动了计算机 &等待几秒钟,然后登录它读取数据库的窗口服务.
If I start the computer & login then it can not read the database, but if i have start the computer & wait for a few seconds and then log into the window service it reads the database.
推荐答案
我敢打赌你的连接字符串中有这个:
I bet you have this in your connection string:
Integrated Security=SSPI
或类似的东西.
现在运行该服务的帐户 (NT AUTHORITYSYSTEM
) 尝试连接到数据库 - 并且无法连接,因为它没有被授权这样做.
Now the account that service is running under (NT AUTHORITYSYSTEM
) tries to connect to the database - and can't since it's not authorized to do so.
您可以:
- 在您的 SQL Server 中为
NT AUTHORITYSYSTEM
创建一个登录名,并为其提供应用所需的必要权限
- either create a login for
NT AUTHORITYSYSTEM
in your SQL Server and give it the necessary permissions it needs for your app
或:
您在 SQL Server 中创建一个特定的应用程序用户帐户(登录到 SQL Server 和数据库中的用户)并将您的连接字符串更改为:
you create a specific application user account in SQL Server (login to SQL Server and user in your database) and change your connection string to:
User ID=(your app account);pwd=YourPassword
这篇关于登录失败.用户“NT AUTHORITYSYSTEM"登录失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!