[#1725] Fix bug where we're trying to close using a null connection

The problem is that the code was:

```python
try:
    connection = self.read_engine.connect()
    # ...
finally:
    connection.close()
```

But if `self.read_engine.connect()` raised an exception, `connection` would
never be defined, but we would still try to call `connection.close()`, which
would in turn raise:

```
UnboundLocalError: local variable 'connection' referenced before assignment
```

This would also hide the exception raised when calling `.connect()`, so we
wouldn't know what was the original problem.

This commit fixes it by making sure the `connection` variable exists.