Asp. Net Logon failure error message when connecting to SQL Server data

Source: Internet
Author: User
Tags iis sql access
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.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.