Improved database connection handling for Model

Signed-off-by: Darren Hill <dchill42@gmail.com>