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.
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.
|show 5 more comments|
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.