Fix for bug where sql connections were not being closed.