Moved database handling to App class to prevent possible crash when ServiceApplication was not yet initialized
Added additional saveguards to ensure that a service connection is established