moved local connection to try statement