I realised that I could have spent the last twenty years putting all my tech knowledge online. Well, I didn't, but as they say, the best time to plant trees is 20 years ago, the second best time is now. So here's all the random programming stuff I've come across that might be helpful. Note: this isn't really questions and answers - more just answers from me!

Login failed for user 'NT AUTHORITY\NETWORK SERVICE'

0 votes

After our server minions 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.

asked Mar 8 in .NET by Ralpharama (360 points)

Please log in or register to answer this question.

...