#425 Make sure database cursor is always being closed