Login failed for user ASPNET or NETWORKSERVICE


Symptoms

When attempting accessing InstantKB.NET i receive the following message:

Cannot open database requested in login 'InstantKB'. Login failed for user 'MACHINENAME\ASPNET' or 'MACHINENAME\NETWORKSERVICE'.

Cause

This is because by default the database connection string uses a trusted connection. When a client is accessing SQL Server via a trusted connection the database your accessing must have the default trusted connection account within the user list with db_owner rights to the target database.

Resolution

To enabled trusted connections for your InstantKB database open SQL Server enterprise manager. Expand your database within enterprise manager and right-click the users node. Select the New database user option and a dialog will appear.

If your running Windows 2003 from the Login name drop down list select the NETWORKSERVICE account then tick the do_owner name option within the Permit in Database Role area.

If your running Windows 2000 or XP from the Login name drop down list select the ASPNET account then tick the do_owner name option within the Permit in Database Role area.

Apply your settings

If the Windows accounts is not listed within the Login Name drop down list please contact your system administrator and ask them to add the account to the Security / Logins area within enterprise manager.

Using a trusted connection is only recommended for development purposes. This should be changed to use a dedicated SQL Server user account with all the correct permissions once you move into a live environment.