Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#SQL-ServerN-Tier
Hi can anyone tell me that in a 3tier win application, policies like 'avoid inserting duplicate username' should be implemented in the BLL, or in database (as stored procedures) ?
Posted 9-Jul-11 5:50am
mahraja241
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can do that in following ways
 
Check if duplicate
Create a method to check the username is already exists in database
public bool IsUsernameExists(string strUsername)
{
  //Check the Username is exists in database Ex Query like SELECT * FROM Table WHERE [UserName]=@strUsername

}
Or
 
Throw the exception
Put a constraint for the UserName column in table. If you try to save duplicate name then it will raise the error, based on the error you can throw the appropriate message to the user.
 
Now you decide.
  Permalink  
Comments
Wonde Tadesse at 9-Jul-11 23:42pm
   
5+
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

thanks, so if I do that in BLL, it reduces one level of propagating exceptions, but also it needs to refer to database twice, first to see if it exists,next insert the record. so which one is preferred?!
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You can do it in both ways. However if you ask me which one I prefer, I would go implementing in BLL. It is not as such good way of implement such kind of validation in DB level. One draw back is propagating the exception from DAL to BLL and then to UI is one step down than propagating from BLL to UI. So without messing around in DB, it is much better implementing in BLL. See thatraja example carefully.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Generally I would put things like this in the business logic layer – after all, it is business logic. However, in the special case of unique constraints on what is presumably a table key, simply setting the primary key (or, if it's not the key column, a unique constraint) on the table will give you this as a bonus side effect so you don't actually need to write any code anywhere. (That assuming you're using a relational database as the data storage layer, of course.)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Firstly, do you want to use any built-in tool? Nextly, if you want a simple validation, then YES, surely that can be done in BLL. Put a simple validation by checking the Data Set you have on that moment and run validation block or function. Stored Procedure can also be used and in that case definitely your application would have a better performance.
 
Finally, if you can give your BLL and DAL then I can write the code for you also. Obviously, if do not have any other problem giving code.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 9,225
1 OriginalGriff 5,395
2 Peter Leow 4,100
3 Maciej Los 3,540
4 Abhinav S 3,333


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 13 Jul 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid