Fixed username db lookup and added db open error handling