Monday, March 26, 2012

Login failed for user localpcname\ASPNET

When I ran my web site using the VS 2005 runtime, the same code ran fine, even the connection.

But when I created an entirely new site and used http, how the login isn't working and it's trying to use ASPNET instead of localpcname\myloginname. When I was using the VS 2005 runtime, it passed my credentials, not the ASPNET user.

(p.s. I changed the pcname to say localpcname for purpose of this post, it actually is using my actual pcname)

System.Data.SqlClient.SqlException: Login failed for user 'localpcname\ASPNET'.

How can I fix this and why is this happening?

Here's my connection string. Again, this string is working fine when using the VS 2005 runtime for a web site project:

<connectionStrings>
<add name="MyConn" connectionString="Data Source=(local); persist security info=False; Initial Catalog=MyTestData; Trusted_Connection=Yes"/>
</connectionStrings>

The DB is local, in IIS, the virtual directory is set to only use Integrated Windows Authentification, so those are not the issue. The issue is, it's passing ASPNET login, not my own now..why?

You're encountering an authentication issue when connecting to SQL. This error indicates that SQL didn't 'recognize' the connectied account from asp.net application. For example, if you deploy your website under IIS and connect to SQL server, actually IIS will use 'ASPNET' account (or 'NT AUTHORITY\NETWORK SERVICE' for IIS6.0) to connect to SQL. The solution is to add the .NET account to SQL logins (in Management Studio, Security->Logins) and give proper permissions to the account.

You can take a look at "Login failed for user <user>" topic in VS2005 documentation.


Thanks...but I actually ended up adding <identityimpersonate="true" /> to my web.config

0 comments:

Post a Comment