Login failed. Login failed for user 'NT AUTHORITY\SYSTEM'

放肆的年华 提交于 2019-12-17 18:37:10

问题


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.

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 AUTHORITY\SYSTEM' " 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.


回答1:


I bet you have this in your connection string:

Integrated Security=SSPI

or something similar.

Now the account that service is running under (NT AUTHORITY\SYSTEM) tries to connect to the database - and can't since it's not authorized to do so.

You can:

  • either create a login for NT AUTHORITY\SYSTEM in your SQL Server and give it the necessary permissions it needs for your app

OR:

  • 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
    



回答2:


Go to security tab under your database.

Under security, Click to expand the Users tab.

Find weather NT AUTHORITY\SYSTEM is present.

If not, Right click on users, Click on new user

In new user window, general tab change the user type to windows user.

Select the User name to, NT AUTHORITY\SYSTEM you will have to find it in the Advanced tab, find now, and select system.

Similarly for login name, browse and find NT AUTHORITY\SYSTEM.

And in the membership tab to the left, select all the required boxes and click ok.

Probably this would fix your issue. Hope this helps.




回答3:


I actually just changed the permissions for the NT AUTHORITY\SYSTEM user in SQL Server and this worked for me.




回答4:


I removed Trusted_Connection=yes from connection string and it worked perfectly.




回答5:


you can add this on Connection string

persist security info=True




回答6:


The simple solution is to check your web.config file and make sure one of these is part of the database connection string:

Trusted Connection=false

OR

Integrated Security=True


来源:https://stackoverflow.com/questions/6894651/login-failed-login-failed-for-user-nt-authority-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!