fix database open/close