Refactor code to close the database in ProgFrag

- Initialize, open and close the database in one piece of code instead of
  getting the values in different parts of the code without closing the
  database.