ASP.NET Error Message: Login failed for ‘NT AUTHORITYNETWORKSERVICE’


If you are developing against a local SQL Server 2005 database in Visual Studio you may not notice this error message until you attempt to access an ASP.NET page that attempts to read or write to your database from an external client (or browser not launch via VStudio)... the reason is because VStudio runs with elevated administrative previledges on the local dev machine.  While there are several ways to surpress this error, here are a few options you might consider:


 



  1. Modify the Web.config file to impersonate a user that has appropriate previledges for read/write access to your database.
    <system.web>
             <identity impersonate="true" userName="username" password="password" />
    <system.web>

    So you might have noticed that this is a little concerning... putting username/password in the web.config, but you can chose to encrypt this to make it more secure.  Otherwise try option #2.

  2. Open SQL Server Management Studio and grant the 'NT AUTHORITY\NETWORK SERVICE' account to the Role Membership of db_datareader and db_datawriter.

  3. A better option yet would be to force the user to login either via forms-based login or windows-based login and use ASP.NET Membership to control authentication to the site... ensure that appropriate users then are associate with a group that then has reader/writer permission on the database.  See here for details: http://msdn2.microsoft.com/en-us/library/yh26yfzy.aspx

Get-R-Done!

Skip to main content