Instantiate database object at top-level
Use correct error for internal failure