changed possition of opening db connection