Implemented persistent database connections.

Thanks Anssi Kääriäinen and Karen Tracey for their inputs.