First thing you need to clear if you are using windows authentication and you are not mentioning any username password in your connection string then:
What happens when you run your code through localhost: when you run your wcf test client from localhost, it will be able to communicate to database as local debug mode application is calling database by your account’s service. So it has access to database because devenv.exe is running under your user account.
But when you deploy your web service in IIS. Now understand this service runs under IIS not under your account. So you need to assign access rights to IIS service to access the sql server for windows authentication. Here your web service would not be able to communicate to the SQL server because of access rights issue and Login Failed for user_______ (here your user will come)
So if you are using windows authentication to connect your database, you just have to change the IIS Application pool settings. You need to change IIS Application pool’s identity to local System.
Below are the Steps for windows authentication WCF:
1) Open IIS (windows+R (run) then type inetmgr, then click ok)
2) double click your PC name under Connections
3) Click Application Pools
4) Select your app pool (DefaultAppPool)
5) Then under actions on the right click Advanced Settings:
6) Go to Process Model section and
7) click on Identity.
8) Now select LocalSystem.
Now open your sql server management studio:
open run-> then type ssms ->then press ok
In ssms, login using your windows authentication account.
Open security tab expand logins tab then you will be able to view your account.
Now open properties of your account
go to userMapping then select the database you want to connect
then check the role membership services you want to use for the selected database. click ok.
(For network services i.e. intranet users you need to configure above settings for NT AUTHORITYSYSTEM user too)
add Trusted_Connection=True; property in your connection string. Save it & deploy the web service. Restart app pool.
you will be able to connect the database now.

- Remove From My Forums
-
Question
-
User709978785 posted
Any Ideas on how to fix this issue?
Visual Studio 2005, Windows 7 64bit, SQL Server 2005 Express
Cannot open database «sql2» requested by the login. The login failed.
Login failed for user ‘IIS APPPOOLDefaultAppPool’.
Answers
-
User709978785 posted
Turns out the issue was with IIS 7.5 and the default Identity setting, it is set to ApplicationPoolIdentity and Not NetworkService.
Who knew?
-
Marked as answer by
Anonymous
Thursday, October 7, 2021 12:00 AM
-
Marked as answer by
All replies
-
User709978785 posted
Turns out the issue was with IIS 7.5 and the default Identity setting, it is set to ApplicationPoolIdentity and Not NetworkService.
Who knew?
-
Marked as answer by
Anonymous
Thursday, October 7, 2021 12:00 AM
-
Marked as answer by
-
User805414602 posted
Hi Jackxxx & dotnetruler,
Thanks for your posts…helped me to solve the issue after few hours of head scratching and a good night sleep.
But one thing…Jackxxx, it would have been helpful to know where you changed the settigns for «ApplicationPoolIdentity» for a newbie like me :-). I did some search and found I can change them as shon in the image below (and hope I did it the right way,
coz my ASP.net application started working!)[Edit: noticed the image does not show up properly in R.H.S], So just select Application Pool -> a pool entry -> Advanced Settings… (from Edit Application Pool section) -> Process Model (from Advanced Setting dialog box)
[Thanks http://www.sharemyimg.com/ for allowing to upload image files and to share them !]

-
User103321928 posted
Please tell me where you found this setting to change it. I’ve been fighting with this error for way too long now and I do not know IIS 7.5 or ASP.Net too well yet and I cannot find where to change this.
Please feel free to e-mail me direct at
tim_robinson@live.comI sure will appreciate it as I need to get this solved today before my customer has a fit.
-
User709978785 posted
Open IIS, double click your PC name under Connections, Click Application Pools, Select your app pool (DefaultAppPool), Then under actions on the right click Advanced Settings, Go to Process Model section and click on Identity. Now select
NetworkService.To open IIS, click your start button and enter IIS into the search field.
hope this helps.
-
User103321928 posted
Hey Jackxxx
Sorry for not reading the entire posts…
I changed the DefaultAppPool identity to a couple different things and it kept failing
So just for fun I figured I’d change it to my username/password by specifying the account and finally it began working….
But could that be a security risk/issue? Is there something in the Windows security somewhere I might need to change so that Network Service will work instead of having to use my Administrator account?
Thanks so much for your help.
-
User1848458564 posted
Your user credentials work probably because you are an Administrator on that machine. The problem is that the connection will fail again if you change your password later.
-
User-308628221 posted
@dotnetruler Your solution rocked.
I am surprised why that wasn’t marked as answer as well! It explains in detail what to do.
Also wondering, when changing the Identity of the app pool to network service, I noticed Application Pool Identity as being recommended. Why change to Network Service? Why not just add the default app pool user in Sql server logins and give it access to
the db?Any thoughts!
-
User-1827764150 posted
ckenk, if you set it up to run as Network Service, you’re not leveraging the new security features of IIS. You should leave that setting as-is (i.e. ApplicationPoolIdentity).
What you want to do is go to your SQL server, and add an SQL login for «IIS APPPOOLDefaultAppPool».
The reason MS stopped using NETWORK SERVICE or LOCAL SYSTEM is that there can be security issues between processes sharing those accounts.
Alternately, you can create a restricted domain account, and use it as your Application Pool process identity, and grant it permissions to your database.
-
User1848458564 posted
Unfortunately I never could find a user with the name «APPPOOLDefaultAppPool» on my Win 2008 system so I always have to switch to «Network User». Any ideas how to give permissions to DefaultAppPool?
-
User-1827764150 posted
Because it’s not a real windows account, you can’t user the «Search» button. Just enter the account name ‘IIS APPPOOLDefaultAppPool’, set your security settings, and click OK.
[IMG]http://i871.photobucket.com/albums/ab272/mike300zxt/SQLLogin-1.jpg[/IMG]
-
User1848458564 posted
Great! Thanks for the quick reply. I’ll try that for SQL.
I also figured DefaultAppPool impersonates IIS_IUSRS. So for my web application that needed write access to the application folder, I just needed to give Write access to IIS_IUSRS.
-
User1848458564 posted
Thanks jobran456 for reply, but this thread suggests not to use NetworkService
in IIS 7+ due to security considerations. Instead it is recommended to use
ApplicationPoolIdentity as default Identity setting. This is by default in IIS 7 and later but you need also check for the followings (summarized from this thread):- Set Read permission for
IIS_IUSRS on the the web application’s local directory. IIS_IUSRS is used when Anonymous Authentication is enabled. - Create a new SQL Login (user) as «IIS APPPOOLDefaultAppPool» and give it
db_owner role membership.
- Set Read permission for
-
User1028487728 posted
Excellent solutions from many people thanks for your support like this …. cheers 🙂
B. Rathinakumar
-
User-895120540 posted
To: mike300zxt
Thank you, your solution worked for me!
What you want to do is go to your SQL server, and add an SQL login for «IIS APPPOOLDefaultAppPool».
The reason MS stopped using NETWORK SERVICE or LOCAL SYSTEM is that there can be security issues between processes sharing those accounts.
Alternately, you can create a restricted domain account, and use it as your Application Pool process identity, and grant it permissions to your database.
-
User-1034524349 posted
Thanks mike300zxt that worked for me too, I had to then cick Server Roles and tick sysadmin also, I hope that doesnt open up any can of worms.
Cheers,

-
User482576241 posted
I prefer matching the IIS defaults to the SQL Server settings. Open your SQL Server Configuration Manager by opening «Run…» and running «sqlservermanager10.msc.» Check the «Log On As» (by default «LocalSystem») of your SQL Server (it should be «running»).
Now open your IIS Manager by running «,» in the left panel click «Application Pools,» then in the right panel click «Set Application Pool Defaults…» In the «Process Model» section of the dialog which pops up, select the same login method as your SQL Server
that we checked earlier. I’m using the default setting, so on my local machine for development I use «LocalSystem» for both.Alternatively you can configure a new «Login» under the «Security» folder on SQL Server as others have mentioned. The easiest way to do this is using SQL Server Management Studio.
I prefer my approach though because then I don’t have to change my connection strings and authentication method for SQL Server.
Cheers 🙂
I am new to both ASP.NET and SQL Server.
I have IIS8 installed on my Windows 8 PC, together with SQL Server Express 2012. Given my ignorance, I have just set everything up using default values.
I have a very small web site set up in its own folder and set up in IIS 8 as a virtual folder under the default web site. I have also set up a very simple database called ‘StockControl’ via SSMS, which contains one table called ‘Colours’ which has two columns.
One page in the website is a simple ASP.NET form which runs on localhost without any problems.
On the second page in the website I added a GridView ASP.NET control, letting Expression Web 4 generate the connection string and place it in a web.config file. I tested the SQL query and the connection as I went along and both came back as successful. So
far, so good.However, when I try to run the page in the browser I get the error message:
Server Error in ‘/’ Application.
Cannot open user default database. Login failed.
Login failed for user ‘IIS APPPOOLDefaultAppPool’.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot open user default database. Login failed.
Login failed for user ‘IIS APPPOOLDefaultAppPool’.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): Cannot open user default database. Login failed. Login failed for user 'IIS APPPOOLDefaultAppPool'.]
I have spent two days trying to find out what I have done wrong and even uninstalled and re-installed SQL Server just in case i’d totally messed up and corrupted the database.
I would really appreciate some help please.
User1210182733 posted
This is my connection string:
<add name=»MovieDBContext»
connectionString=»Data Source=.SQLExpress;Initial Catalog=aspsamples;Integrated Security=True»
providerName=»System.Data.SqlClient»
/>
I tried following the documentation here
http://www.asp.net/web-forms/tutorials/deployment/visual-studio-web-deployment/deploying-to-iis
and I ran the query and it executed succesfully:
IF NOT EXISTS (SELECT name FROM sys.server_principals WHERE name = 'IIS APPPOOLDefaultAppPool')
BEGIN
CREATE LOGIN [IIS APPPOOLDefaultAppPool]
FROM WINDOWS WITH DEFAULT_DATABASE=[master],
DEFAULT_LANGUAGE=[us_english]
END
GO
CREATE USER [ContosoUniversityUser]
FOR LOGIN [IIS APPPOOLDefaultAppPool]
GO
EXEC sp_addrolemember 'db_owner', 'ContosoUniversityUser'
GO
I am receiving now an error:
Server Error in '/MvcMovie' Application. Cannot open database "aspsamples" requested by the login. The login failed. Login failed for user 'IIS APPPOOLDefaultAppPool'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Cannot open database "aspsamples" requested by the login. The login failed. Login failed for user 'IIS APPPOOLDefaultAppPool'. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [SqlException (0x80131904): Cannot open database "aspsamples" requested by the login. The login failed. Login failed for user 'IIS APPPOOLDefaultAppPool'.] System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +671 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +116 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1012 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +6712511 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +152 System.Data.SqlClient.SqlConnection.Open() +229 System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +102 [EntityException: The underlying provider failed on Open.] System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +11455575 System.Data.EntityClient.EntityConnection.Open() +142 System.Data.Objects.ObjectContext.EnsureConnection() +97 System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +66 System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +51 System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +220 System.Linq.Queryable.FirstOrDefault(IQueryable`1 source) +330 System.Data.Entity.Internal.EdmMetadataRepository.QueryForModelHash(Func`2 createContext) +331 System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(InternalContext internalContext, ModelHashCalculator modelHashCalculator, Boolean throwIfNoMetadata) +112 System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +280 System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +66 [DataException: An exception occurred while initializing the database. See the InnerException for details.] System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +162 System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +225 System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +208 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +235 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +36 System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +71 System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +21 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +446 System.Linq.Enumerable.ToList(IEnumerable`1 source) +80 MvcMovie.Controllers.MoviesController.Index() +31 lambda_method(Closure , ControllerBase , Object[] ) +79 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +261 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39 System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +34 System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +124 System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +838059 System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +15 System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +33 System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +838644 System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +51 System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18033
How can I get IIS APPOOLDefaultAppPool to connect to my database or how should I develp a connection?
User1210182733 posted
This is my connection string:
<add name=»MovieDBContext»
connectionString=»Data Source=.SQLExpress;Initial Catalog=aspsamples;Integrated Security=True»
providerName=»System.Data.SqlClient»
/>
I tried following the documentation here
http://www.asp.net/web-forms/tutorials/deployment/visual-studio-web-deployment/deploying-to-iis
and I ran the query and it executed succesfully:
IF NOT EXISTS (SELECT name FROM sys.server_principals WHERE name = 'IIS APPPOOLDefaultAppPool')
BEGIN
CREATE LOGIN [IIS APPPOOLDefaultAppPool]
FROM WINDOWS WITH DEFAULT_DATABASE=[master],
DEFAULT_LANGUAGE=[us_english]
END
GO
CREATE USER [ContosoUniversityUser]
FOR LOGIN [IIS APPPOOLDefaultAppPool]
GO
EXEC sp_addrolemember 'db_owner', 'ContosoUniversityUser'
GO
I am receiving now an error:
Server Error in '/MvcMovie' Application. Cannot open database "aspsamples" requested by the login. The login failed. Login failed for user 'IIS APPPOOLDefaultAppPool'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Cannot open database "aspsamples" requested by the login. The login failed. Login failed for user 'IIS APPPOOLDefaultAppPool'. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [SqlException (0x80131904): Cannot open database "aspsamples" requested by the login. The login failed. Login failed for user 'IIS APPPOOLDefaultAppPool'.] System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +671 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +116 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1012 System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +6712511 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +152 System.Data.SqlClient.SqlConnection.Open() +229 System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +102 [EntityException: The underlying provider failed on Open.] System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +11455575 System.Data.EntityClient.EntityConnection.Open() +142 System.Data.Objects.ObjectContext.EnsureConnection() +97 System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption) +66 System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator() +51 System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source) +220 System.Linq.Queryable.FirstOrDefault(IQueryable`1 source) +330 System.Data.Entity.Internal.EdmMetadataRepository.QueryForModelHash(Func`2 createContext) +331 System.Data.Entity.Internal.ModelCompatibilityChecker.CompatibleWithModel(InternalContext internalContext, ModelHashCalculator modelHashCalculator, Boolean throwIfNoMetadata) +112 System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +280 System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +66 [DataException: An exception occurred while initializing the database. See the InnerException for details.] System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +162 System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +225 System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +208 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +235 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +36 System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +71 System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator() +21 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +446 System.Linq.Enumerable.ToList(IEnumerable`1 source) +80 MvcMovie.Controllers.MoviesController.Index() +31 lambda_method(Closure , ControllerBase , Object[] ) +79 System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +261 System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39 System.Web.Mvc.Async.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41() +34 System.Web.Mvc.Async.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33() +124 System.Web.Mvc.Async.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49() +838059 System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult) +15 System.Web.Mvc.Async.<>c__DisplayClass2a.<BeginInvokeAction>b__20() +33 System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult) +838644 System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult) +28 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +65 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +51 System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult) +42 System.Web.Mvc.Async.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar) +15 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +51 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18033
How can I get IIS APPOOLDefaultAppPool to connect to my database or how should I develp a connection?
Basically this problem comes up when we work with Asp.Net Application With IIS Server. I got this error while working with Asp.Net MVC Application. When I run My MVC application suddenly I got this error:
“System.Data.SqlClient.SqlException was unhandled by user code: Login failed for user ‘IIS APPPOOLDefaultAppPool’” and database connection couldn’t open.
There are some step for solving this problem.
- Go to your Run Window and there you type “Inetmgr” and click oK ( Means Go to IIS Server).
- Here you will IIS Server window , from this window you go to “Application pools” and then select “DefaultAppPool” Right click on it and select “Advance Settings” and click on that.

- When you will click on Advance settings link it will open Advance setting window there you select “Identity” (In Process Modal) and Change the path from ApplicationPoolIdentity to LocalSystem.

When you click on this Path, three dotted buttons, a window will open from there “Built-in-Account “radio button contain a dropdown box , from this dropdown box you change this path and the click OK.
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 APPPOOLDefaultAppPool') BEGIN CREATE LOGIN [IIS APPPOOLDefaultAppPool] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english] END GO CREATE USER [WebDatabaseUser] FOR LOGIN [IIS APPPOOLDefaultAppPool] GO EXEC sp_addrolemember 'db_owner', 'WebDatabaseUser' GO
If one uses trusted connection to a sqlserver database under Windows 7 and II7 one might get the error message “Login failed for user ‘IIS APPPOOLDefaultAppPool’.” when trying to run a web application. There are several articles for this but all points to a different GUI than mine (earlier versions of Windows7/IIS7?).
Update: as I lightly noted, to give the apppool SystemLocal rights is Not the right way to go.
Set up the application pool in IIS
Fire up Internet Information Services Manager. (windowbutton-iis-return)
Find the Application Pools item in the Connections toolbar. One can reuse the default application pool or create a new one. Go for the latter since it is slightly more complicated and hence more fun.


or in Win8:
(I don’t grok what Managed pipleline mode does.)
Select your newly created application pool and the advanced settings. Change the Process model to LocalSystem.
(I had planned to create a “better” account with the proper limited rights but ran out of time. Someone else…?)
Update: Don’t change to LocalSystem, instead add the user to allowed SQLServer logins as noted in the bottom here. I suggest “IIS AppPoolMySite” for now.
The recommended Microsoft solution is to create a separate account. However, if your solution is small, you can instead add the ‘IIS APPPOOLDefaultAppPool’ user as a database user in your SQL instance, then providing the proper ‘User Mappings’ to the databases you need the DefaultAppPool user to access. You may not necessarily be able to search for this user, but you can still enter it in the ‘Login name’ field in the “Login – New” window as “IIS APPPOOLDefaultAppPool” (without the quotes).
Follow this link as a reference and pay attention to the last post: http://social.msdn.micro…-4a71-a448-3e3eef9ee404/
Application pool settings

Getting to advanced settings.
Application pool advanced settings
Site settings
Now change your web application to use this application pool. This could be made simpler by moving the menu for this to the same place as the other menus. To make the story short – select your site and look to the right of the IIS manager.


Site advanced settings.
Site advanced setting IIS7.

Application pool.
Application pool in IIS7.
Set up Sqlserver
Honour those who should.
To add a new user to SQLServer go to your database->security and add user connected to IIS APPPOOLDefaultAppPool. This way the user can log in to the database.
Sqlserver -> new login.
New login to database. Don’t forget to change default database to appropriate.
Then go to the SQLServer->security and add this user to be allowed to login to the server through the user and properties.
The users of a database.
That is all there is to it.
Tags: database, iis, iis apppool, iis7, sqlserver
This entry was posted on Sunday, October 18th, 2009 at 21:16 and is filed under Code and Development.
You can follow any responses to this entry through the RSS 2.0 feed.
Both comments and pings are currently closed.