Properly open and close database connection for each request