Optimising sql connection