
我遇到以下錯誤:
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
答案1
您需要使用使用者名稱「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-從-networkservice-更改為-apppoolidentity.aspx和http://learn.iis.net/page.aspx/624/application-pool-identities/
以下是 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
我分配了所有者權限,但您的應用程式可能能夠獲得較低的權限。授予您可以逃脫的最低權限通常被認為是良好的做法。