简体   繁体   English

授予对IIS APPPOOL \\ DefaultAppPool的数据库访问权限

[英]Grant database access for IIS APPPOOL\DefaultAppPool

I have an ASP.NET application that uses Entity Framework running on IIS 7.5 and it needs to access (first create) the database, but I always get an exception Login failed for user 'IIS APPPOOL\\DefaultAppPool' . 我有一个使用在IIS 7.5上运行的Entity Framework的ASP.NET应用程序,它需要访问(首先创建)数据库,但是我总是遇到一个异常: Login failed for user 'IIS APPPOOL\\DefaultAppPool'

I've already tried creating a login for that user in SQL Server Management Studio as many posts recommend, but it didn't help at all... I've added IIS APPPOOL\\DefaultAppPool login with Windows Authentication to the server Security>Login section, but I still see the exception when I load the website. 我已经尝试过像许多帖子所建议的那样,在SQL Server Management Studio中为该用户创建登录名,但是它根本没有帮助...我已将带有Windows身份验证的IIS APPPOOL \\ DefaultAppPool登录添加到服务器的“安全性”>“登录”中部分,但在加载网站时仍然看到异常。

I've also tried creating a different app pool, moving my application to it and adding its name to login section of the database server but it didn't help too. 我也尝试过创建一个不同的应用程序池,将我的应用程序移至该池,并将其名称添加到数据库服务器的登录部分,但这也无济于事。

Ofcourse, if I set the identity of the DefaultAppPool to LocalSystem or NetworkService it successfully creates and accesses the database, but I don't want to use these identities for my app pool as they have high-level permissions and puts the server in a security risk... 当然,如果我将DefaultAppPool的标识设置为LocalSystemNetworkService则它可以成功创建并访问数据库,但是我不希望对我的应用程序池使用这些标识,因为它们具有高级权限,并且使服务器处于安全状态。风险...

Please advice me something. 请给我一些建议。 I'd like to know how to give my app pool permissions to access the database... 我想知道如何授予我的应用程序池访问数据库的权限...

I don't know what exactly caused my problem, but I've found a solution myself. 我不知道是什么导致了我的问题,但是我自己找到了解决方案。

Somehow IIS APPPOOL\\DefaultAppPool doesn't even need any additional permissions for the database server, it can connect to it even if its name is not included in the database's Logins section. 某种程度上, IIS APPPOOL\\DefaultAppPool甚至不需要数据库服务器的任何其他权限,即使它的名称未包含在数据库的“ Logins部分中,它也可以连接到它。 Simply, the database it creates is somehow very tightly coupled with the IIS APPPOOL\\DefaultAppPool entity (whatever it actually is) AND, if you delete the database that belongs to IIS APPPOOL\\DefaultAppPool or any other pool and then try to create a new database with the same application pool, it acts as if the database wasn't actually deleted previously, but as if you were trying to access what's remaining from it with an account that didn't created it. 简而言之,它创建的数据库以某种方式与IIS APPPOOL\\DefaultAppPool实体(无论实际上是什么)紧密结合在一起,并且,如果删除了属于IIS APPPOOL\\DefaultAppPool或任何其他池的数据库,然后尝试创建一个新数据库对于相同的应用程序池,它的作用就像以前实际上并未删除数据库一样,但是就像您试图使用未创建数据库的帐户访问数据库中剩余的内容一样。 Maybe it's not very easy to understand what I'm saying, but I think that the deletion of the database that belongs to an instance of an application pool not only deletes it, but also "unlinks" it from that pool and when you try to create a new database in the same application pool it just doesn't allow you, because you are "unlinked" from it, even if it doesn't even exist anymore. 也许很难理解我的意思,但是我认为删除属于应用程序池实例的数据库不仅会删除它,还会从该池中“取消链接”它,并且在您尝试在同一个应用程序池中创建一个新数据库,它只是不允许您使用,因为即使它不再存在,您也已与该数据库“取消链接”。 Maybe there still are some "links" in the database server, but they are not valid anymore, so the application pool is treated as something that tries to override the remainder of the database but doesn't have permissions to do it. 也许数据库服务器中仍然存在一些“链接”,但是它们不再有效,因此将应用程序池视为试图覆盖数据库其余部分但没有权限执行此操作的对象。

SO FINALLY THE FIX!!! 终于解决了!!!

To fix this, just create a new application pool with a different name than the one that had previously created the database, move your application there and it'll work. 要解决此问题,只需使用与先前创建数据库的名称不同的名称创建一个新的应用程序池,然后将您的应用程序移至该位置即可使用。 I'm not sure if you can then create application pool with the same name and then create the database, but I guess yes. 我不确定是否可以使用相同的名称创建应用程序池,然后创建数据库,但是我想是的。 And, of course, restart IIS (I restart it through Internet Information Services (IIS) Manager ) after you create a new pool. 并且,当然,在创建新池之后,重新启动IIS(我通过Internet Information Services (IIS) Manager重新启动Internet Information Services (IIS) Manager

UPDATE!!! UPDATE!

Yes, I've just tested and now can confirm that you can create an application pool with the same name, but before this you have to delete it not only from IIS Manager's application pool's window but also from Users directory of your computer (where users' files are stored, ie C:\\Users) and then you can create a new pool with the same name. 是的,我刚刚进行了测试,现在可以确认您可以使用相同的名称创建一个应用程序池,但是在此之前,您不仅需要从IIS管理器的应用程序池的窗口中删除它,还必须从计算机的Users目录(用户存储文件(即C:\\ Users),然后您可以创建一个具有相同名称的新池。

It took me a long time to find out this strange behavior. 我花了很长时间才发现这种奇怪的行为。 I did it through lots of error and trial, so I'm happy to share it so that maybe someone one day will fix a similar problem faster than me. 我通过大量的错误和尝试来做到这一点,所以我很乐意分享它,以便也许某天某人会比我更快地解决类似的问题。

Good luck guys! 祝大家好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM