Administrator

Administrator

  • Tech Writer
  • 2.2k
  • 1.5m

Correct pattern to use connections

Mar 24 2003 10:41 AM
Hi Im trying to figure out what's the best way to connect and disconnect from my database. Im building a web based application. What i'm doing right now is providing a connection in the constructor for every class that will need one. I store the connection in a variable and then use it in whatever methods need the connection. Since I need to specifically close the connection, I do so in the destructor. I figured if I do this, then the db connection closing can be done in the background whenever the object is garbageCollected and save myself a bunch of open-closes, plus I dont have to worry about every method having to open or receive its own connection and then closing it. Is there something flawed in my thoughts? any Ideas? Best Regards JR

Answers (2)