{"record":{"id":"fa745b324336d81a","repo":"NationalSecurityAgency/ghidra","slug":"connection-with-database-not-established","errorCode":null,"errorMessage":"Connection with database not established","messagePattern":"Connection with 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":137,"sourceCode":"\t/**\n\t * Query the given server with the parameters provider by {@code queryInfo}.\n\t * \n\t * @param queryInfo a query info object containing the settings for the 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 to use; can be null\n\t * @return the result object containing the retrieved similar functions; null if the query\n\t *         was cancelled\n\t * @throws QueryDatabaseException if the query execution fails\n\t * @throws CancelledException if the query is cancelled by the user\n\t */\n\tpublic SFQueryResult querySimilarFunctions(SFQueryInfo queryInfo,\n\t\t\tSFResultsUpdateListener<SFQueryResult> listener, TaskMonitor monitor)\n\t\t\tthrows QueryDatabaseException, CancelledException {\n\t\tSFQueryResult result = null;\n\t\ttry {\n\t\t\tif (database == null || database.getStatus() != Status.Ready) {\n\t\t\t\tthrow new QueryDatabaseException(\"Connection with 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\t//\n\t\t\t// Perform the required initialization:\n\t\t\t// -Initialize signature generator\n\t\t\t// -Hash the functions\n\t\t\t// -Create the query\n\t\t\t// -Create the staging\n\t\t\t//\n\n\t\t\tQueryNearest query = generateQueryNearest(queryInfo, monitor);\n\t\t\tint localNumStages = numStages;","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/facade/SimilarFunctionQueryService.java#L119-L155","documentation":"Thrown by SimilarFunctionQueryService.querySimilarFunctions when the internal database handle is null or its Status is not Status.Ready. The Status enum is Unconnected/Busy/Error/Ready; only Ready means the connection is established and idle enough to query. Querying in any other state is rejected before any signatures are generated.","triggerScenarios":"Calling querySimilarFunctions before the service was connected/initialized, after it was closed/disposed, or while a previous query still marks the database Busy.","commonSituations":"Forgetting to setDatabase / connect before querying; calling query after service.dispose(); a prior query left the DB in Error state (auth/network failure); concurrent use of one service from two threads.","solutions":["Ensure SimilarFunctionQueryService is connected (database != null and getStatus()==Ready) before invoking; call your connect/initialize path first.","Do not call any query method after dispose()/close(); obtain a fresh service instance.","If Status is Error, inspect database.getLastError() and re-establish the connection.","Serialize access to a single service instance to avoid Busy contention."],"exampleFix":"// before\nSFQueryResult r = service.querySimilarFunctions(queryInfo, listener, monitor);\n// after\nif (service.getStatus() != Status.Ready) {\n    throw new IllegalStateException(\"BSim database not ready: \" + service.getStatus());\n}\nSFQueryResult r = service.querySimilarFunctions(queryInfo, listener, monitor);","handlingStrategy":"validation","validationCode":"if (service.getStatus() != Status.Ready) {\n    throw new IllegalStateException(\"BSim database not ready: \" + service.getStatus());\n}\nSFQueryResult r = service.querySimilarFunctions(queryInfo, listener, monitor);","typeGuard":"static boolean isReady(FunctionDatabase db) {\n    return db != null && db.getStatus() == Status.Ready;\n}","tryCatchPattern":"try {\n    service.querySimilarFunctions(queryInfo, listener, monitor);\n} catch (QueryDatabaseException e) {\n    if (e.getMessage().contains(\"not established\")) { /* (re)connect then retry */ }\n}","preventionTips":["Always connect/initialize the service before querying.","Never call query methods after dispose(); create a new instance.","On Error status, read getLastError() and re-establish the connection.","Do not share one service across concurrent threads."],"tags":["bsim","facade","connection","lifecycle","state"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}