Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I'm very much confused for the reason of declaring DAL(Data Access Layer) Class as static. If i declare DAL(Data Access Layer) class as non static will it leads to transaction problem.

For Example: My application DAL(Data Access Layer) classes are in non static. Whenever users access that it will create new instance of that class. When two users accessing same field in table in same time. Will it leads to transaction when any user is in slow net connection.
Posted
Comments
Dean Oliver 22-Mar-12 2:13am    
What technology are you using? EF? Linq To Sql? old ADO.NET? And where did you read it has to be static? and whats in this class? Please provide sample code. thanks

1 solution

It's not the users that are the problem - it's the potential for having two instances within the same application.

Even if you declare it as static, you can have two users accessing the same database from different PCs - which could cause transaction problems and has to be kept in mind when designing any system. Static or non-static will not affect that.

Static just prevents there being two incompatible versions of the data layer as seen by the program. It's not necessary, and can prevent some patterns (such as the Factory pattern) being used. Static, Singleton, or instanced - it is a matter of personal preference to a large degree.
 
Share this answer
 
Comments
HarisJayadev 22-Mar-12 6:11am    
Thanks for your answer. Can you elaborate me some more.
HarisJayadev 17-Jun-12 23:58pm    
Please elaborate me more

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900