asp.net|server|sql|sqlserver| Error | data
Symptoms
When you create a trusted connection from asp.net to SQL Server, you may receive the following error message:
Login failed for user ' MachineName\ASPNET
For computers this run Internet information Services (IIS) 6.0, you could receive the following error message:
Login failed for user ' Machinename\networkservice
Note: In particular when using integrated security (including the integrated Security=sspi property in the connection string), one of the above error messages occurs.
Reason
When you use ASP.net, for aspnet_wp.exe (or for applications running on IIS 6.0, W3wp.exe) and requests to SQL Server, the default security context is the ASPNET_WP account (or for the IIS 6.0 for applications running on, for NetworkService accounts). By default, the ASPNET_WP account (or the NetworkService account for an application running on IIS 6.0) does not have any permissions in SQL Server, so it cannot access the database.
Solution
To resolve this issue, use one of the following methods.
• Programmatically change the security context of the ASP.net worker process to a user with the correct SQL Server permissions.
Or
• Change the default configuration of the ASP.net to enable the ASP.net worker process to start and run in the context of a user who has the correct permissions in SQL Server.
Or
• Grant the correct permissions on SQL Server so that the aspnet_wp account (or, for an application running on IIS 6.0, the NetworkService account) has the appropriate permissions to access the required resources.
State
This phenomenon is due to the design.
Steps to reproduce this problem
1. Create a new Microsoft Visual Basic. NET Web application on any computer that is running ASP.net and SQL Server concurrently.
2. Add the following code to the Page_onload event for the WebForm1.aspx page created with the project: Dim con as New System.Data.SqlClient.SqlConnection ("Data source= localhost;integrated Security=sspi;database=northwind ")
Con.open ()
Con.close ()
3. Build the project, and then open the WebForm1.aspx page in the browser. You will see the error message that is described in the "Symptoms" section of this article.