We have a .NET object that reads / writes a lot to the database. Throughout the life cycle of this object (or the asp page that uses it), it can go to the database with a request / update anywhere from 1 to 10 times.
Instead of opening and closing a database connection every time an object needs to get into the database, it simply opens a database connection during instance creation, and then closes the connection during the object's completion event. Is this a bad practice?
It was assumed that since the object enters the database each time it is created (and usually several times), it would be better to just open the connection at the beginning of the life of the object, and then close it at the end.
Another alternative is to open and close the database connection before and after each request / operation.
What is the best practice to maximize performance?
**** **** update Thanks for the guys advice. Can anyone talk more about the method of opening / closing a connection inside the events of creation / completion of an object and the consequences of this?
source share