added in try except for connecting to the database