Unable to open database when website hosted in IIS

烂漫一生 提交于 2021-01-04 04:16:28

问题


When I run my website from Visual Studio it all works fine. Now I am trying to move forward and start testing the multi tenancy part, so I had to move my website to IIS.

For some reason I can't get access to the database. The error I get when I open a page that requires database access is:

Cannot open database "GWD" requested by the login. The login failed. Login failed for user 'IIS APPPOOL\gwd'.

Exception Details: System.Data.SqlClient.SqlException: Cannot open database "GWD" requested by the login. The login failed. Login failed for user 'IIS APPPOOL\gwd'.

Another forum describes how to add NT AUTHORITY\NETWORK SERVICE. But that doesn't resolve the issue. I did create the NT AUTHORITY\NETWORK SERVICE and added the dbowner for all existing databases (including master) but no result.

I am out of ideas, can anybody help?


回答1:


You'll need to change the application pool identity to NETWORK SERVICE as well. Fire up Internet Information Services (IIS) Manager, drill down to Application Pools, and select the Application Pool that you're using. (Not sure? Drill down to your virtual directory under Sites on the left side and then click Basic Settings on the right.) Then click your Application Pool, click Advanced Settings, and then change Identity under Process Model to NetworkService.

In SQL Server Management Studio, you'll need to add the NT AUTHORITY\NETWORK SERVICE user under Security for your database, but it sounds like you already did that.




回答2:


You see the error "Cannot open database "GWD" requested by the login. The login failed. Login failed for user 'IIS APPPOOL\gwd....." because you copy the application to the IIS server and the membership provider has been added in the web.config file without an applicationName attribute.

I suggest you add an “applicationName” attribute to your provider declaration. Example:

<membership>
<providers>
<add name ....
.
.
.
.
applicationName="/yourWebApp" />

</providers>
</membership>

Just look in the aspnet_Application table to find out the application name that was used when creating the users/data during development.

I hope it helps.




回答3:


@Nicholas Piasecki has offered one potential solution, and the other would be to leave the app pool as it, and instead grant the AppPoolIdentity that it is currently running under access to the database instead.

First, you'd need to add a new Windows login to the SQL Server for the user: 'IIS APPPOOL\gwd'.

Once you do that, you'll be able to add that user to the database with the appropriate permissions, just as you did for Network Service.




回答4:


i think you must read this article Configure IIS, asp.net and SQL Server from codeproject In this article you will learn how to configure IIS and SQL Server using Network SERVICE (with screenshot)

Content of this article

  • Install IIS
  • Configure IIS for Network SERVICE
  • Configure SQL Server PERMISSIONs



回答5:


On your IIS Select the application pool you use on your site > right click > click Advance Settings. On Identity select "NetworkService"

enter image description here

On you database [SQL] Create Login for NT AUTHORITY\NETWORK SERVICE. Modify User Mapping

enter image description here



来源:https://stackoverflow.com/questions/14662271/unable-to-open-database-when-website-hosted-in-iis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!