Fix for jrcportal #974

Connection were not released in case of exections. Changes contain fixes.