After our server people did some MS SQL database restores from some old backups to find some data, some .NET websites we had on the server started showing an error.

(note I couldn’t see the error and had to disable custom errors from remote only, see here http://tech.ralpharama.co.uk/1/viewing-errors-remote-machine-after-sql-restores-broke-sites

Server Error in '/' Application.
Cannot open database "MyDatabaseName" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.Data.SqlClient.SqlException: Cannot open database "MyDatabaseName" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.

Curious. Okay, so if we open the MyDatabaseName database up in MS SQL Management Studio, click on the database, then click on security, then click on ‘Users’.

Look at the list, there’s no NT AUTHORITY\NETWORK SERVICE there. 

So, right click and Add New User. Give it the name ‘NT AUTHORITY\NETWORK SERVICE’ then click on the … next to the ‘Login name’. Now in the ‘Select Login’ box, type NT AUTHORITY\NETWORK SERVICE and click on ‘Check Names’. It should highlight and change to [NT AUTHORITY\NETWORK SERVICE]. Click okay.

Now scroll down and find, under ‘Role Members’ db_datareader, and db_datawriter, check both boxes and then save the config and re-run the website.

Last modified: April 27, 2023

Author

Comments

Write a Reply or Comment

Your email address will not be published.