Move database connection variable into anonymous function.