I want my data access level to be built very modular.
Therefore, I have data retrieval methods that are sometimes called directly from the business layer and sometimes called by other data retrieval methods to create object dependencies.
What is the best way to work with database connections in DAL?
a) Create a new connection in each method and delete it later.
Good: easy to write and work.
Bad: many connections open and close. (Performance?)
b) Pass the connection as an optional argument.
Good: I can reuse an open connection for multiple teams.
Bad: I need to track the ownership of the connection (who should close it?) And cannot use very neat “used” statements.
c) Something else? (Perhaps the connection is as a singleton?)
This is the first time I am writing a real DAL, so I really could use some help from your experienced people.
EDIT: How it matters, this is an ASP.Net website project.
source
share