title: Trying to GRANT ASP.NET access to sample Database from my book
body: <p>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:</p>
  
  <p>Murach's ASP.NET 4 Web Programming with C# 2010 (Murach: Training &amp; Reference)</p>
  
  <p>The book came with two files to do this:</p>
  
  <blockquote>
    <p>"grant_access_windows_7_vista.bat" which runs this file: "grant_access_windows_7_vista.sql"</p>
  </blockquote>
  
  <p>Here are the files respectively:</p>
  
  <pre><code>@ECHO off
  
  :: batch file for
  :: Murach's ASP.NET 4 Web Programming with C# 2010
  :: company: Mike Murach &amp; 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
  </code></pre>
  
  <p>Here is the .sql file:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I then run the Query including the word exit and here is what I get:</p>
  
  <pre><code>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'.
  </code></pre>
  
  <p>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.</p>
  
  <p>Here is what I have tried... still with no luck:</p>
  
  <blockquote>
    <p>IIS 7 is trying to use the IIS application pool identity to access your SQL database.</p>
    
    <p>So you must first grant the IIS 7 apppool access to SQL server.</p>
    
    <p>To do that, go in SQL Server Management Studio -> Server Instance -> Security -> Logins -> New Login</p>
    
    <p>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.</p>
    
    <p>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.</p>
  </blockquote>
  
  <p>All I got was this error when I tried the things above:</p>
  
  <pre><code>"IIS APPPOOL\ASP.NET v4.0" is not a valid name because it contains invalid characters. (Microsoft SQL Server, Error: 15006
  </code></pre>