Shawn Wildermuth's Rants and Raves

Thanks for visiting my blog! See more about me here: About Me

Remember That Those Connections are Precious
Remember That Those Connections are Precious
April 11, 2002

The most common error I see in badly scalable database code is reckless use of the connection object. For all multi-user database programming (which accounts for most of the work these days), database connections are a limited resource. Don’t let it be your code that is hanging on to his connection way after you are finished with it. I am *not* saying that all work can be done disconnected. I am simply asking you to keep in mind that Connections are precious things. Try to do these two things:

  • Open Connections as Late as possible.
  • Close Connections as Early as possible.

Most people concentrate on closing their connections early. This is good and well known. But I have seen more than my share of code (including mine!) that opened database connections too early.