Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
2.39/5 (6 votes)
See more: , +
I am working on web application. Suddenly i got the error "System.Data.SqlClient.SqlException was unhandled by user code: Login failed for user 'IIS APPPOOL\DefaultAppPool". Can anybody help.
Posted
Updated 20-Mar-17 11:05am
Comments
Maciej Los 8-Mar-13 17:22pm    
Check that sql services were started...
[no name] 8-Mar-13 23:39pm    
Yes, SQL Server services already working.
Maciej Los 9-Mar-13 12:44pm    
See my tip: http://www.codeproject.com/Tips/543989/How-to-enum-SQL-Server-instances-in-network. Run exe and check the named instances of MS SQL Server.
[no name] 14-Mar-13 4:56am    
Hello Maciej, Thank you for thee reply it couldn't resolve my problem.
Madhav Gunjal 9-Dec-15 1:10am    
try this link, i was also facing same problem and i overcome it with the help of this link
http://stackoverflow.com/questions/7698286/login-failed-for-user-iis-apppool-asp-net-v4-0

go to iis -> application pools -> find your application pool used in application -> click it and then click 'Advance Settings' in Actions panel. Find 'Identity' property and change it to localsystem.
Please mark as solution if it solve your problem.
 
Share this answer
 
Comments
U@007 26-Apr-13 8:56am    
it's correct 5+ :).
pratapyadav 23-Nov-13 6:03am    
thanks
roni.net 21-Jul-14 16:21pm    
Many thanks. The SOlution is very good
sha_server 27-Aug-14 3:48am    
thanks for the resolution
Member 11230360 26-Nov-14 1:24am    
Thank you.. it worked.
With reference to following link:

http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/deploying-to-iis[^]

Create a grant script for the new databases

When the application runs in IIS on your development computer, the application accesses the database by using the default application pool's credentials. However, by default, the application pool identity does not have permission to open the databases. So you have to run a script to grant that permission. In this section you create the script that you'll run later to make sure that the application can open the databases when it runs in IIS.



Run the following script:
IF NOT EXISTS (SELECT name FROM sys.server_principals WHERE name = 'IIS APPPOOL\DefaultAppPool')
BEGIN
    CREATE LOGIN [IIS APPPOOL\DefaultAppPool] 
      FROM WINDOWS WITH DEFAULT_DATABASE=[master], 
      DEFAULT_LANGUAGE=[us_english]
END
GO
CREATE USER [WebDatabaseUser] 
  FOR LOGIN [IIS APPPOOL\DefaultAppPool]
GO
EXEC sp_addrolemember 'db_owner', 'WebDatabaseUser'
GO
 
Share this answer
 
Comments
Member 11332478 13-Jan-15 23:13pm    
its not working to my system,tell me how to delete this procedure?
jcpc91 25-Mar-15 13:34pm    
this not work 'IIS APPPOOL\DefaultAppPool' doesn't exist in windows server 2008 r2
Member 11608707 15-Apr-15 4:23am    
many many thanks.It works!!
Member 11241204 4-Jul-15 4:49am    
Great.... It works ....Many Thanks :)
Member 11457847 27-May-16 16:03pm    
thanks. its work
Run This Script :

CREATE LOGIN [IIS APPPOOL\DefaultAppPool] FROM WINDOWS
GO
--USE Table Name
GO
CREATE USER [IIS APPPOOL\DefaultAppPool] FOR LOGIN [IIS APPPOOL\DefaultAppPool]
GO
EXEC sp_addrolemember 'db_datareader', 'IIS APPPOOL\DefaultAppPool'
GO
EXEC sp_addrolemember 'db_datawriter', 'IIS APPPOOL\DefaultAppPool'
GO
 
Share this answer
 
v2
Comments
CHill60 22-Sep-14 17:56pm    
Resolved a year ago!
xTMx9 28-Jul-16 16:30pm    
This worked for me instead of the solution
Cipherc 11-Feb-17 0:11am    
Cool .. works beautifully
Member 10188322 30-Apr-20 5:45am    
It's work fine
Member 14909715 15-Sep-21 0:37am    
Thanks a lot This solution helped me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900