Ensure db connection is closed before script exits

This is required in django 1.4, but was closed automatically back
in 1.2 when it was created.