DAL/BLL Best Practices
-
I am looking to create an Data Access Layer and Business Logic Layer for a new web site. I am looking for suggestions on the best practice on how to handle the database connection from the DAL. I have seen examples where every function in the DAL creates a connection, runs the query, and then closes the connection based on the connection string passed into the DAL. With connection pooling this doesnt seem to be a big issue. Is this the best method for a web application since it is stateless? Or, is it better for the BLL to create a connection and pass the connection into the DAL? How is the best way to get the connection string from the Web.config file to the DAL? Does the BLL pass the connection string into the DAL or is there a better way? I am looking at using ASP 2.0 but I didnt want to use the table adapter wizard. Any examples would be greatly appreciated.
-
I am looking to create an Data Access Layer and Business Logic Layer for a new web site. I am looking for suggestions on the best practice on how to handle the database connection from the DAL. I have seen examples where every function in the DAL creates a connection, runs the query, and then closes the connection based on the connection string passed into the DAL. With connection pooling this doesnt seem to be a big issue. Is this the best method for a web application since it is stateless? Or, is it better for the BLL to create a connection and pass the connection into the DAL? How is the best way to get the connection string from the Web.config file to the DAL? Does the BLL pass the connection string into the DAL or is there a better way? I am looking at using ASP 2.0 but I didnt want to use the table adapter wizard. Any examples would be greatly appreciated.
All I can say is what I do... I keep ALL connection/database/sql out of the BLL. This way if my application moves to a different database all I have to do is rewrite the DAL and the rest of your application works fine. I also only use the presentation layer to do presentation; the BLL is what messes with the data.
-
All I can say is what I do... I keep ALL connection/database/sql out of the BLL. This way if my application moves to a different database all I have to do is rewrite the DAL and the rest of your application works fine. I also only use the presentation layer to do presentation; the BLL is what messes with the data.
-
Do you have each function in the DAL also handle the connection? How do you recommend the best way to have the DAL get the connection string?
Recently I've been using typed datasets, I think they open a connection each time. In my older projects I did open a connection for each request. However, my apps are internal workflow applications though, so they are not serving 100,000 hits /sec or anything :p I put the connection string in app.config.