Reduce database usage - open connection to database right before prepare of query