Fixed bugs when db is not opened in shell mode.