Question

Why is a data layer used while we can write most of the code in stored procedures itself? What are the advantages and disadvantages in it? Data layer is an important layer in 3 tier architecture, which handles all the database related tasks. My question is that, whether we can achieve this using a stored procedure itself in most of the cases? In that case, what is the major advantage in using that layer?

EDIT:

The question was just to get clear idea about the usage of data layer and database stored procedures. I have got an answer below which helped me in that.

Was it helpful?

Solution

The 3-tier approach is for when you wish to maybe use different Database Engine types.

From Multitier architecture

Data tier

This tier consists of database servers. Here information is stored and retrieved. This tier keeps data neutral and independent from application servers or business logic. Giving data on its own tier also improves scalability and performance.

OTHER TIPS

In stored procedure goes your query logic, in data access layer you connect with database engine

MSDN, N-Tier-Architecture-and-Tips have good insight on n-tier architecture

You can't unit test stored procs very easily because you can't easily mock the data in the database

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top