Microsoft KB Archive/316989

= Error message when you create a trusted data connection from ASP.NET to SQL Server: &quot;Login failed for user: 'AccountName'&quot; =

Article ID: 316989

Article Last Modified on 9/21/2007

-

APPLIES TO


 * Microsoft ASP.NET 1.1
 * Microsoft ADO.NET 1.1
 * Microsoft ASP.NET 1.0
 * Microsoft .NET Framework 1.1 Service Pack 1
 * Microsoft SQL Server 2000 Standard Edition
 * Microsoft SQL Server 7.0 Standard Edition
 * Microsoft ADO.NET 2.0

-



This article was previously published under Q316989



SYMPTOMS
When you create a trusted connection from Microsoft ASP.NET to Microsoft SQL Server, you may receive the following error message:

Login failed for user 'MachineName\ASPNET

For computers that run Internet Information Services (IIS) 6.0, you may receive the following error message:

Login failed for user 'NT AUTHORITY\NETWORK SERVICE'

Note You receive either of these error messages specifically when you use integrated security (when you include the integrated security=sspi attribute in a connection string).



CAUSE
When you use ASP.NET, the default security context is the ASPNET account (or NetworkService account, for an application that runs on IIS 6.0) for both Aspnet_wp.exe (or W3wp.exe, for an application that runs on IIS 6.0) and the request to SQL Server. By default, the ASPNET account (or NetworkService account, for an application that runs on IIS 6.0) does not have any permissions in SQL Server, and therefore it cannot access the database.



RESOLUTION
To resolve this issue, use one of the following methods:
 * Method 1 Programmatically change the security context of the ASP.NET worker process to a user who has the correct SQL Server permissions.
 * Method 2 Change the default configuration of ASP.NET so that the ASP.NET worker process starts and runs under the context of a user who has the correct permissions in SQL Server.
 * Method 3 Grant the correct permissions in SQL Server so that the ASPNET account (or NetworkService account, for an application that runs on IIS 6.0) has the appropriate access to the required resources.

Note This method will make all the Web applications on the server have the corresponding right on the computer that is running SQL Server.



STATUS
This behavior is by design.



Steps to reproduce the issue
 Create a new Microsoft Visual Basic .NET Web application on a computer that is running both ASP.NET and SQL Server.  Add the following code to the Page_Load event of the Webform1.aspx page that was created by using the project: Dim con As New System.Data.SqlClient.SqlConnection(&quot;data source=localhost;integrated security=sspi;database=northwind&quot;) con.open con.close  Build the project, and then open the Webform1.aspx page in the browser. You receive the error message that is mentioned in the &quot;Symptoms&quot; section.

<div class="references_section">