I am trying to set up this book to run database apps under IIS, and grant ASP.NET access to the database. The name of the book is:
Murach's ASP.NET 4 Web Programming with C# 2010 (Murach: Training & Reference)
The book came with two files to do this:
"grant_access_windows_7_vista.bat" which runs this file: "grant_access_windows_7_vista.sql"
Here are the files respectively:
@ECHO off
:: batch file for
:: Murach's ASP.NET 4 Web Programming with C# 2010
:: company: Mike Murach & Associates, Inc.
:: date: March 16, 2011
::
:: Uses SQLCMD utility to run a SQL script that grants
:: ASP.NET access to the Halloween database.
ECHO Attempting to grant ASP.NET access to the Halloween database . . .
sqlcmd -S localhost\ -E /i grant_access_windows_7_vista.sql
ECHO.
ECHO If no error message is shown, then access has been granted to the database.
ECHO.
PAUSE
Here is the .sql file:
use Halloween
go
sp_grantlogin 'IIS APPPOOL\ASP.NET v4.0'
go
sp_grantlogin 'IIS APPPOOL\ASP.NET v4.0'
go
sp_grantdbaccess 'IIS APPPOOL\ASP.NET v4.0'
go
sp_addrolemember 'db_owner', 'IIS APPPOOL\ASP.NET v4.0'
go
exit
I then run the Query including the word exit and here is what I get:
Msg 15401, Level 11, State 1, Procedure sp_grantlogin, Line 49
Windows NT user or group 'IIS APPPOOL\ASP.NET v4.0' not found. Check the name again.
Msg 15401, Level 11, State 1, Procedure sp_grantlogin, Line 49
Windows NT user or group 'IIS APPPOOL\ASP.NET v4.0' not found. Check the name again.
Msg 15401, Level 16, State 1, Line 1
Windows NT user or group 'IIS APPPOOL\ASP.NET v4.0' not found. Check the name again.
Msg 15410, Level 11, State 1, Procedure sp_addrolemember, Line 75
User or role 'IIS APPPOOL\ASP.NET v4.0' does not exist in this database.
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'exit'.
I am just a beginner and do not know much about SQL or IIS. Any help making this work would be greatly appriciated. I will try to do my part as well by searching GOOGLE, but if someone could explain why this is not working that would be fantasic.
Here is what I have tried... still with no luck:
IIS 7 is trying to use the IIS application pool identity to access your SQL database.
So you must first grant the IIS 7 apppool access to SQL server.
To do that, go in SQL Server Management Studio -> Server Instance -> Security -> Logins -> New Login
Login name will be "IIS APPPOOL\ASP.NET v4.0". This is because everytime you create an application pool in IIS7, it will create an identity which uses the same name as your app pool. In your case, you are using the default app pool which comes with asp.net 4.
Then on your database, go to Security -> Logins -> New login , give it a alias name, then select your user object you added in your previous step (IIS APPPOOL\ASP.NET v4.0) then give it db_owner (or whatever your needs are) schemas/role privileges.
All I got was this error when I tried the things above:
"IIS APPPOOL\ASP.NET v4.0" is not a valid name because it contains invalid characters. (Microsoft SQL Server, Error: 15006