{"record":{"id":"fdc80ae2d39b73fb","repo":"NationalSecurityAgency/ghidra","slug":"connection-to-database-not-established","errorCode":null,"errorMessage":"Connection to database not established","messagePattern":"Connection to database not established","errorType":"validation","errorClass":"QueryDatabaseException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/facade/SimilarFunctionQueryService.java","lineNumber":200,"sourceCode":"\t}\n\n\t/**\n\t * Query the given server for similar function overview information\n\t * @param overviewInfo is details of the overview query\n\t * @param listener is the listener to be informed of the query status and incremental results \n\t * \t\tcoming back, may be null\n\t * @param monitor the task monitor\n\t * @return the ResponseNearestVector\n\t * @throws QueryDatabaseException if the database connection cannot be established\n\t * @throws CancelledException if the query is cancelled by the user\n\t */\n\tpublic ResponseNearestVector overviewSimilarFunctions(SFOverviewInfo overviewInfo,\n\t\t\tSFResultsUpdateListener<ResponseNearestVector> listener, TaskMonitor monitor)\n\t\t\tthrows QueryDatabaseException, CancelledException {\n\t\tResponseNearestVector response = null;\n\t\ttry {\n\t\t\tif (database == null || database.getStatus() != Status.Ready) {\n\t\t\t\tthrow new QueryDatabaseException(\"Connection to database not established\");\n\t\t\t}\n\t\t\tif (monitor == null) {\n\t\t\t\tmonitor = TaskMonitor.DUMMY;\n\t\t\t}\n\t\t\tif (listener == null) {\n\t\t\t\tlistener = new NullListener<>();\n\t\t\t}\n\n\t\t\tQueryNearestVector query = generateQueryNearestVector(overviewInfo, monitor);\n\t\t\tint localNumStages = numStages;\n\t\t\tif (localNumStages == 0) {\n\t\t\t\tint funcsPerStage = database.getOverviewFunctionsPerStage();\n\t\t\t\tlocalNumStages = overviewInfo.getNumberOfStages(funcsPerStage);\n\t\t\t}\n\t\t\tStagingManager stagingManager =\n\t\t\t\tcreateStagingManager(overviewInfo.getFunctions().size(), localNumStages);\n\n\t\t\ttry {","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/facade/SimilarFunctionQueryService.java#L182-L218","documentation":"Thrown by SimilarFunctionQueryService.overviewSimilarFunctions when the database handle is null or its Status is not Status.Ready. The overview path mirrors querySimilarFunctions' connection guard (note slightly different wording: 'Connection to database not established' vs 'with database'). Only Status.Ready permits the overview query to proceed.","triggerScenarios":"Invoking overviewSimilarFunctions before connecting, after dispose(), or while the database is Busy/Error/Unconnected.","commonSituations":"Service not initialized before overview call; reused after close; prior query left Error state; concurrent access marking Busy.","solutions":["Connect/initialize the service so database.getStatus()==Ready before calling overviewSimilarFunctions.","Do not call after dispose(); create a new service instance instead.","On Error, inspect getLastError(), re-establish connection, then retry.","Avoid concurrent calls on one service instance."],"exampleFix":"// before\nResponseNearestVector v = service.overviewSimilarFunctions(overviewInfo, listener, monitor);\n// after\nif (service.getStatus() != Status.Ready) {\n    throw new IllegalStateException(\"BSim DB not ready\");\n}\nResponseNearestVector v = service.overviewSimilarFunctions(overviewInfo, listener, monitor);","handlingStrategy":"validation","validationCode":"if (service.getStatus() != Status.Ready) {\n    throw new IllegalStateException(\"BSim DB not ready\");\n}\nResponseNearestVector v = service.overviewSimilarFunctions(overviewInfo, listener, monitor);","typeGuard":"static boolean isReady(FunctionDatabase db) {\n    return db != null && db.getStatus() == Status.Ready;\n}","tryCatchPattern":"try {\n    service.overviewSimilarFunctions(overviewInfo, listener, monitor);\n} catch (QueryDatabaseException e) {\n    if (e.getMessage().contains(\"not established\")) { /* reconnect, retry */ }\n}","preventionTips":["Connect the service so status is Ready before overview calls.","Do not reuse a service after dispose().","On Error, inspect getLastError() and reconnect.","Avoid concurrent calls on one service instance."],"tags":["bsim","facade","connection","lifecycle","overview"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}