Hi, Why should I close a DB connection?
I have asked this question somewhat before, but never received a solid answer, like "it's good practice", but why?
I appreciate any input.
| SitePoint Sponsor |




Hi, Why should I close a DB connection?
I have asked this question somewhat before, but never received a solid answer, like "it's good practice", but why?
I appreciate any input.


Many older programming languages has no way of automatically detect when you no longer referr to a resource. The only way to freeing this resource (memory) was to close the connection. This is usaully done automagicly these days so you might say itīs legacy to do so but thatīs not true either. As soon you get into persistent database connections you will now what I mean. If you learn to do whatīs "good practice" from the beginning you donīt have to unlearn it later and it will save you from pulling your hair completely. As we say in Sweden:
Itīs not easy to teach an old dog to sit.
Bookmarks