3

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
bas
  • 13,550
  • 20
  • 69
  • 146
  • 1
    Quickest way seems to be to just add the security for your APPPOOL\gwd login. Try this solution: http://stackoverflow.com/questions/1933134/add-iis-7-apppool-identities-as-sql-server-logons – Jason Haley Feb 02 '13 at 13:26

5 Answers5

10

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.

Nicholas Piasecki
  • 25,203
  • 5
  • 80
  • 91
  • hoh, sometimes solutions given by Microsoft ( docs.microsoft) doesn't seem to work, but this works.. huh!! thnx-- I had a somewhat realted issue with local IIS, and this did it. – Irf Jul 16 '20 at 19:03
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.

Harold Javier
  • 887
  • 2
  • 7
  • 16
1

@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.

Xander
  • 479
  • 1
  • 13
  • 25
1

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
Bhavik Patel
  • 1,466
  • 1
  • 12
  • 28
0

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

tyne
  • 97
  • 5