How to create logging and connect locally hosted website to database?

This post is a continuation of my previous post.Here we will see how we can create a login and connect your web application to the database.

In real life scenarios when we are hosting the website on the IIS and we also have the application pointing to a database then we need to have proper logging and proper permissions set up.If not then we will get a yellow screen saying…

Cannot open database database-name requested by the login. 
The login failed.Login failed for user IIS APPPOOL\App-pool-name.

App-pool-name is generally the name under which you have hosted the website on IIS.

Prerequisites

  • Already hosted website on IIS.
  • Already created database lets say Test.

Steps

  • Expand the security tab and then right click on Logins.

Login

  • Select the new Login option.

NewLogin

  • In general tab put the login name as IIS APPPOOL\app-pool-name.In my case its test.in.So login name is IIS APPPOOL\test.in .

LoginName

  • Click on User Mapping tab on the left and select master and test.Below on the database role membership for master select the db_owner.Click Ok.

User Mapping

  • Point your web application to the Test database.

Point Application To Test Database

Yeah!! Now you have hosted website locally and connected to database as well.

Thanks for reading this post. Keep following me for more updates.