Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have seen weird database access practices in .net. I have seen stored procedures for every database tasks. I have seen every database property name is preceded by it's table name. I have seen fully separate layer/.dll for very few or no business logic. I have seen along with ORMs, there are separate data access layer playing the same role. And with them, I have always heard- "These are the standards you have to maintain".

So, what are the real standards for data access in .net? What are the rules you follow?

share|improve this question
    
Do you mean, what is the default and straight-forward way to access data in a d'base using ASP.NET? –  TeaDrinkingGeek Feb 21 '11 at 17:42
    
ODBC, RDO, DAO, ADO, OLEDB, ADO.NET, ... someone please continue –  Job Feb 23 '11 at 0:51
    
Liked the database access methodology here- ayende.com/Blog/archive/2011/02/23/… And it is successfully used in projects. –  Gulshan Feb 24 '11 at 9:04
add comment

5 Answers 5

The standards are whatever is defined for your project by your team. They vary based on the situation.

"I have seen stored procedures for every database tasks": All stored procedures is not a bad way to go for small apps (to prevent sql injection) or for databases which contain data which could be updated by multiple sources (access database, web app, etc)

"I have seen every database property name is preceded by it's table name" I see this in a lot in older databases so I wonder if it might have been a standard a while back. I think it's overkill though.

"I have seen fully separate layer/.dll for very few or no business logic": Probably someone trying to implement a good design pattern for a small application that didn't really need it.

"I have seen along with ORMs, there are separate data access layer playing the same role": Perhaps the application started with one data access style, and as it grew another got implemented and no one refactored.

share|improve this answer
    
Stored procedures themselves do not prevent SQL injection. The only reliable way to prevent SQL injection attacks is to use parametric queries, which most, if not all, database libraries provide. –  greyfade Feb 22 '11 at 21:59
add comment

There really is no standard in practice unfortunately.

However, for an application with real complexity (i.e. domain modeling) ORMs are the approach advocated by:

share|improve this answer
add comment

There are no standards. Use what works for you, your team, and your project then STICK TO THAT STANDARD.

share|improve this answer
add comment

There is no standard but I don't see this as a bad thing. In agriculture, monoculture is the practice of planting only one type of a crop everywhere - one specific type of corn, soybeans, cotton, etc. The thought was there must be one best answer to the question, "What is the best type of X?" (Side note: The "one best" idea was pushed by large Ag. companies just like large software companies and bloggers push the idea with technology.)

Turns out this idea is wrong. Monocultures are catastrophically vulnerable to disease. Normally, if a farmer's crop gets sick, that farmer loses his/her crop. With a monoculture, a disease will spread across all farms with incredible losses. Diversity prevents this.

Diversity is powerful.

share|improve this answer
add comment

A better question might be, "What Should I Do When I See Absurd-Seeming Coding Standards?"

So, what are the real standards for data access in .net?

There are no "real" standards. Every organization has to come up with their own. If the standards in your organization don't make sense, try to find out why they're there. If you find out why, and still think they don't make sense, challenge them. Chances are, they will draft you to the committee that sets the standards, or ask you to write your own if there aren't any "written-down" standards for your group.

Of course, that assumes you've approached this in a thoughtful, respectful, and mature way. If you haven't done that, expect to be shut down or ignored.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.