{"record":{"id":"3be64546d9379e32","repo":"jumpserver/jumpserver","slug":"cannot-connect-to-database","errorCode":null,"errorMessage":"Cannot connect to database","messagePattern":"Cannot connect to database","errorType":"exception","errorClass":"DatabaseError","httpStatus":null,"severity":"critical","filePath":"apps/libs/ansible/modules_utils/oracle_common.py","lineNumber":99,"sourceCode":"        result, error = None, None\n        try:\n            self.cursor.execute(sql, params)\n            sql_header = self.cursor.description or []\n            column_names = [description[0].lower() for description in sql_header]\n            if column_names:\n                result = [dict(zip(column_names, row)) for row in self.cursor]\n                result = result[0] if len(result) == 1 else result\n            else:\n                result = None\n        except DatabaseError as err:\n            error = err\n        if exception_to_fail and error:\n            self.module.fail_json(msg='Cannot execute sql: %s' % to_native(error))\n        return result, error\n\n    def commit(self):\n        if self._conn is None:\n            raise DatabaseError('Cannot connect to database')\n        self._conn.commit()\n\n    def close(self):\n        try:\n            if self._cursor:\n                self._cursor.close()\n            if self._conn:\n                self._conn.close()\n        except:\n            pass\n","sourceCodeStart":81,"sourceCodeEnd":110,"githubUrl":"https://github.com/jumpserver/jumpserver/blob/6ec464fabd61b95912d539455a3a5f15f5c59fe0/apps/libs/ansible/modules_utils/oracle_common.py#L81-L110","documentation":"Raised by OracleClient.commit when self._conn is None — i.e. commit() was called on a client whose JDBC/DB connection was never established or has been lost. The class guards execute paths with fail_json, but commit() raises DatabaseError directly because there is no connection object to commit on.","triggerScenarios":"Calling commit() after connect() failed but the failure was swallowed (exception_to_fail=False or error ignored); calling commit() after close() or after the underlying connection dropped; the main flow reaching the commit step for user_add/user_change_password without a prior successful connect.","commonSituations":"Oracle asset with wrong host/port/credentials where connect errors were logged but execution continued; network drop mid-task before commit; code paths that call commit() unconditionally after a try/except that swallowed the connect exception.","solutions":["Check the connect step's result/error before calling commit; abort on connection failure","Ensure connect() succeeded (self._conn is not None) — inspect why the connection is missing (credentials, listener, network)","Structure the flow as connect -> execute -> commit -> close with early exit on the first failure"],"exampleFix":"# before\nclient.connect()\nresult, err = client.execute(sql)\nclient.commit()  # DatabaseError if connect failed silently\n\n# after\nclient.connect()\nif client._conn is None:\n    module.fail_json(msg='Oracle connection failed')\nresult, err = client.execute(sql)\nif not err:\n    client.commit()","handlingStrategy":"try-catch","validationCode":"if getattr(client, '_conn', None) is None:\n    module.fail_json(msg='Oracle connection not established; aborting before commit')","typeGuard":"null","tryCatchPattern":"try:\n    client.commit()\nexcept DatabaseError as e:\n    module.fail_json(msg=f'Commit failed: {e}')","preventionTips":["Abort the task as soon as connect fails; never continue to commit","Wrap connect/execute/commit in one try block with early fail_json","Monitor connection liveness for long-running Oracle push tasks"],"tags":["oracle","database","connection","transaction"],"backgroundTag":"database-connection-lost","analyzedSha":"6ec464fabd61b95912d539455a3a5f15f5c59fe0","analyzedAt":"2026-08-28T11:33:00.925Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}