简体   繁体   中英

The login failed.\r\nLogin failed for user 'NT AUTHORITY\\NETWORK SERVICE in c# dot net

I am using entity framework and created DBcontext from package manager.. Everything working fine in localhost, when i tried to publish and access the url through postman the above issue happening, I tried lots of options

  1. NT AUTHORITY\NETWORK SERVICE as the user in sql server
  2. installed core installation support.

some body please help. Below is the response which i am getting from the postman { "status": "failure", "message": "Cannot open database "BigDay" requested by the login. The login failed.\r\nLogin failed for user 'NT AUTHORITY\NETWORK SERVICE'.", "data": null }

It is better to define a username and password for the database to which the program is connected and login with it, and the second way, will reduce security a bit.

I will explain both way below

first way:

  1. open your sql server management
  2. go security folder
  3. go login folders
  4. right click login and click New Login
  5. enter loginname and password
  6. User Mapping Tab select your database and bottom panel in role membership check db_datareader and check db_datawriter.

Then enter this information in the program and connect with this username and password.

second way:

  1. open your sql server management
  2. go security folder
  3. go login folders
  4. right click NT AUTHORITY\NETWORK SERVICE and select properties
  5. in opened dialog select Server Roles
  6. Check sysadmin or server admin and then OK.

在此处输入图像描述

1.Go to SQL Server >> Security >> Logins and right click on NT AUTHORITY\NETWORK SERVICE and select Properties

2.In newly opened screen of Login Properties, go to the “User Mapping” tab. Then, on the “User Mapping” tab, select the desired database – especially the database for which this error message is displayed. On the lower screen, check the role db_owner. Click OK.

Most cases, this should fix the problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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