Take care of db closed connections

this function had to be different so that the cur2 could be created and returned.