resolve problem with disconnecting database if connection was not established yet