created common method for getting database in request thread and bgtask