Put database access inside try block