Fix db connection handling when databse defined per query