Sql-Server

我在哪裡可以找到此 IIS 錯誤“使用者 ‘IIS APPOOLWeb2 登錄失敗”中的使用者

  • September 3, 2012

我遇到以下錯誤:

Cannot open database "testbase" requested by the login. The login failed.

Login failed for user 'IIS APPPOOL\Web2'.

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 "testbase" requested by the login. The login failed.

Login failed for user 'IIS APPPOOL\Web2'.

那麼,我在哪裡可以給這個使用者 Web2 權限呢?(順便說一句,伺服器沒有這樣的使用者,但在 wwwroot 文件夾中Web2有一個名為的文件夾。)Web2

我搜尋答案,但都失敗了,如下所示:

$$ 1 $$將使用者添加IUSR到文件夾並授予其讀取權限。 $$ 2 $$ http://www.codekicks.com/2008/11/cannot-open-database-northwind.html $$ 3 $$ http://blog.sqlauthority.com/2009/08/20/sql-server-fix-error-cannot-open-database-requested-by-the-login-the-login-failed-login-failed-for-user-nt-authoritynetwork-service/

您需要使用使用者名“IIS APPPOOL\Web2”將使用者添加到 SQL Server,並授予該使用者對數據庫的訪問權限。請注意,您不會在搜尋中看到此使用者名,但如果點擊“檢查名稱”,您可能會看到它變為下劃線。

除了管理應用程序池的權限外,使用者實際上並不存在於機器上。

或者,您可以將應用程序池設置為以不同的使用者身份執行。

有關詳細資訊,請參閱http://blogs.iis.net/webdevelopertips/archive/2009/10/02/tip-98-did-you-know-the-default-application-pool-identity-in-iis-7 -5-windows-7-changed-from-networkservice-to-apppoolidentity.aspxhttp://learn.iis.net/page.aspx/624/application-pool-identities/


下面是 SQL Server 登錄列表的範例:

SQL Server 使用者

以下是數據庫登錄列表的範例:

數據庫使用者

以下是數據庫使用者的詳細資訊:(請注意,兩個框的名稱相同。第二個框必須與 SQL Server 登錄列表中的登錄名匹配。)

數據庫使用者詳細資訊


您也可以嘗試使用程式碼而不是 GUI:

USE [master]
GO
CREATE LOGIN [IIS APPPOOL\Web2] FROM WINDOWS WITH DEFAULT_DATABASE=[testbase]
GO

USE [testbase]
GO
CREATE USER [IIS APPPOOL\Web2] FOR LOGIN [IIS APPPOOL\Web2]
GO
EXEC sp_addrolemember N'db_owner', N'IIS APPPOOL\Web2'
GO

我分配了所有者權限,但您的應用程序可能能夠以較低的權限逃脫。通常認為最好的做法是授予您可以逃脫的最低權限。

引用自:https://serverfault.com/questions/422269