Login failed for "IIS AppPool\ASP.NET v4.0" - SQL Server Web

16,029

Solution 1

IIS 7 is trying to use the IIS application pool identity to access your SQL database.

So you must first grant the IIS 7 apppool access to SQL server.

To do that, go in SQL Server Management Studio -> Server Instance -> Security -> Logins -> New Login

Login name will be "IIS APPPOOL\ASP.NET v4.0". This is because everytime you create an application pool in IIS7, it will create an identity which uses the same name as your app pool. In your case, you are using the default app pool which comes with asp.net 4.

Then on your database, go to Security -> Logins -> New login , give it a alias name, then select your user object you added in your previous step (IIS APPPOOL\ASP.NET v4.0) then give it db_owner (or whatever your needs are) schemas/role privileges.

Solution 2

EDIT: Please don't do this -- I wasn't thinking when I originally wrote this answer.

For more details why my original answer isn't a good idea please review the link in the comments below.


Another solution is to go into IIS and edit the application pool itself to use the identity "LocalSystem." This can be found by right click the app pool -> advanced settings -> click Identity's '...' button (right below "Process Model") -> select "LocalSystem" under the Built-in account drop-down.

Doing it this way you don't need to set up a new user in your database.

Share:
16,029

Related videos on Youtube

user127667
Author by

user127667

Updated on September 17, 2022

Comments

  • user127667
    user127667 over 1 year

    I'm trying to migrate a website from SQL Server 2008 Express to SQL Server Web, and the website is having trouble accessing the database. In truth, Express was only ever used by running the website from Visual Studio's builtin web server, so I'm not sure about the configuration working all that well under full-blown IIS 7. At any rate, when I try to access a page that uses Linq to Entities (requiring the website to connect to the database), I get the error "Login failed for 'IIS AppPool\ASP.NET v4.0'". So, I opened SQL Server Management Studio, and I attempted to add a login for the user, but I just get a message stating "Windows NT or user group '*****\Asp.Net v4.0' not found". This happens even after I ask Management Studio to check the name of the user, which it does successfully. Can someone tell me what I'm doing wrong? Also, I'm open to alternative suggestions as well... Everything's running on the same server, so there are no remote connections. For this reason, I'd love to use Windows Authentication if at all possible.

  • Admin
    Admin over 13 years
    @kimphamg: Thanks for the reply. I tried that, but after entering the login name you suggested, Management studio says "Windows NT or user group '[Server Name]\Asp.Net v4.0' not found". Also, since the website hasn't been able to access sql server, I can't seem to find the database in the object explorer of Management Studio. I don't think it's been attached yet...
  • Admin
    Admin over 13 years
    Should I create a local user on the server called "Asp.Net v4.0"?
  • Admin
    Admin over 13 years
    Is that necessary?
  • DIMMACK
    DIMMACK over 13 years
    Wait, are you using IIS 7 or IIS 7.5 ?
  • Admin
    Admin over 13 years
    It's IIS 7.5...
  • DIMMACK
    DIMMACK over 13 years
    You do not need to create a user, because your app pool already created it. Also make sure you execute SQL Server Management Studio as Administrator
  • Admin
    Admin over 13 years
    Thanks kimphamg, I'll try that. Also, about your other suggestion to add the new sql server user's privelages to the database... Should I attach the database using Management Studio? Is that something which IIS would normally take care of? Sorry, I guess these are kind of newbie questions...
  • DIMMACK
    DIMMACK over 13 years
    Yes, attach your database to SQL server using Management Studio. It is much easier to manage your database this way! Also look at IIS to see which application pool your website uses. By looking at your error, your app pool seems to be 'ASP.NET v.4.0'.
  • Admin
    Admin over 13 years
    @kimphamg: It worked! I created a sql server login and granted it permissions on the necessary databases. Thanks!