Database connection (Cannot open database "VRM" requested by the login.)

0

I'm getting Error when running my website on host. Unable to open database connection for the following application(s) .... Received exception. Message: Cannot open database "VRM" requested by the login. The login failed. Login failed for user Login failed for user 'IIS APPPOOL\DefaultAppPool'.

Login failed for user 'IIS APPPOOL\DefaultAppPool'.

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 "VRM" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\DefaultAppPool'.

Source Error:


Line 33:             {
Line 34: 
Line 35:                 throw;
Line 36: 
Line 37:             }


Source File: D:\Final Code\VRM\VRM\Manager\LoginManager.cs    Line: 35

Stack Trace:


[SqlException (0x80131904): Cannot open database "VRM" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\DefaultAppPool'.]

.net
sql-server
networking
asked on Stack Overflow Apr 13, 2019 by Imran Amanat

1 Answer

0

Looking at your connection strings, either change them both to Username/password auth, or grant that account access to the target database. You can provision access with a script like the following, which will grant the app pool identity full control on the target database:

use vrm

create login [IIS APPPOOL\DefaultAppPool] from windows
create user [IIS APPPOOL\DefaultAppPool] for login [IIS APPPOOL\DefaultAppPool]
grant control to [IIS APPPOOL\DefaultAppPool]

You can run the script after connecting to SQL Server using SQL Server Management Studio or the sqlcmd.exe command line tool.

For a production application, you would want to limit the permissions granted to the application identity. This will help protect against SQL Injection vulnerabilities. EG

use vrm

create login [IIS APPPOOL\DefaultAppPool] from windows
create user [IIS APPPOOL\DefaultAppPool] for login [IIS APPPOOL\DefaultAppPool]
create role AppUser
grant select, execute, insert, update, delete on schema::dbo to AppUser
alter role AppUser add member [IIS APPPOOL\DefaultAppPool]

User contributions licensed under CC BY-SA 3.0