6

I know this is a very basic question. But I am really not able to comprehend what should we have in BLL. Let me take an example.
Let us consider a Login.aspx web page, which is used to facilitate user login.
In this case Login.aspx will have two textboxes and one login button.(Presentation Layer).
Data Access Layer will have functions to check if username and password are correct.


I don't think I need something else in this page. So what will I have in BLL. If you want to add some functionality that should come in BLL, please add.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Vaibhav Jain
  • 33,887
  • 46
  • 110
  • 163

3 Answers3

7

No, the BLL checks if the username and password are correct. The DAL is only for data access.

kprobst
  • 16,165
  • 5
  • 32
  • 53
  • so you mean, on click of login button, i will call a function in BLL which checks if username and password is correct by passing them to DAL – Vaibhav Jain Jan 22 '10 at 16:42
  • @kprobst, should I write a Sql query to in BAL – Vaibhav Jain Jan 22 '10 at 16:45
  • 1
    For example, let's say that you're retrieving a password hash based on the user name, and verifying it against the provided password. The DAL is used to pull the data off the table where that is stored, the BLL is used to verify the hash. In general no logic should reside in the database, whether business or not. That goes in the business layer. This is not always possible, but you should strive to keep as much code out of the DB as possible. Consider the DAL (ORM, whatever) part of the DB for this purpose. – kprobst Jan 22 '10 at 17:03
  • No, the DAL is used only to pull the data from the database. That's the definition of DAL, unless you're confusing it with ORM. – kprobst Jan 22 '10 at 19:58
5

"Data Acess Layer will have functions to check if username and password are correct" - wrong. The BLL will do that, the DAL will only retrieve (or try to retrieve) the user's information, without doing any checking on it.

Otávio Décio
  • 73,752
  • 17
  • 161
  • 228
  • so in this case, I am executing a SP, then where should I add Parameters to that SP, in BLL or DAL – Vaibhav Jain Jan 22 '10 at 16:44
  • Your BLL should ask the DAL to call the SP, and the BLL will interpret its results upon its return. The DAL is only a mostly brainless conduit. – Otávio Décio Jan 22 '10 at 16:47
  • so it means in BLL I will add parameters to that SP and pass it to DAL for execution. – Vaibhav Jain Jan 22 '10 at 16:49
  • No, the BLL knows nothing about SP's and parameters. The DAL should have a method that receive whatever parameters necessary and create the database call with such parameters. – Otávio Décio Jan 22 '10 at 16:52
  • Then what is the use of BLL here. I could have call function of DAL directly from Presentation Layer. – Vaibhav Jain Jan 22 '10 at 16:55
3

You should have something like this:

The UI calls BL.SaveUsernameAndPassword(string user, string pass);

BL.SaveUsernameAndPassword should validate the strings, and then call DAL.SaveUsernameAndPassword(string user, string pass);

DAL.SaveUsernameAndPassword should put these parameters into your SQL query and execute it, with the assumption that the data is valid

Fiona - myaccessible.website
  • 14,481
  • 16
  • 82
  • 117