{"record":{"id":"3ceb78bede9b43a8","repo":"NationalSecurityAgency/ghidra","slug":"database-does-not-exist-3ceb78","errorCode":null,"errorMessage":"Database does not exist: {}","messagePattern":"Database does not exist: (.+?)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/file/H2FileFunctionDatabase.java","lineNumber":92,"sourceCode":"\t\tvectorTable = new H2VectorTable(vectorFactory, vectorStore);\n\t}\n\n\t@Override\n\tpublic void close() {\n\t\tvectorTable.close();\n\t\tsuper.close();\n\t}\n\n\t@Override\n\tprotected void setConnectionOnTables(Connection db) {\n\t\tvectorTable.setConnection(db);\n\t\tsuper.setConnectionOnTables(db);\n\t}\n\n\t@Override\n\tprotected Connection initConnection() throws SQLException {\n\t\tif (getStatus() != Status.Ready && !fileDs.exists()) {\n\t\t\tthrow new SQLException(\n\t\t\t\t\"Database does not exist: \" + fileDs.getServerInfo().getDBName());\n\t\t}\n\t\treturn super.initConnection();\n\t}\n\n\t@Override\n\tprotected void generateRawDatabase() throws SQLException {\n\t\tBSimServerInfo serverInfo = fileDs.getServerInfo();\n\t\tif (fileDs.exists()) {\n\t\t\tthrow new SQLException(\"Database already exists: \" + serverInfo.getDBName());\n\t\t}\n\t\ttry (Connection c = fileDs.getConnection()) {\n\t\t\t// do nothing - should throw exception on error\n\t\t}\n\t}\n\n\t@Override\n\tprotected void createDatabase(Configuration config) throws SQLException {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/file/H2FileFunctionDatabase.java#L74-L110","documentation":"Thrown as an SQLException by H2FileFunctionDatabase.initConnection() when the database status is not Ready and the underlying H2 file data source does not exist on disk. This is a guard that prevents attempting to open an H2 connection to a database file that was never created or has been deleted.","triggerScenarios":"Occurs when initConnection() is called on an H2FileFunctionDatabase whose fileDs.exists() returns false and the database hasn't already reached Status.Ready. This happens when: the URL points to a file path that doesn't exist, the database was never created (generateRawDatabase/createDatabase was never called), or the file was deleted externally.","commonSituations":"Specifying an H2 BSim URL to a database that hasn't been generated yet. Typo in the file path. The database file was manually deleted from disk. Trying to query a database that was dropped by another Ghidra instance.","solutions":["Verify the H2 database file path in the BSim URL is correct and the file exists on disk.","If the database should exist, run the BSim database creation command to generate it first.","Check file system permissions on the directory containing the database.","Use fileDs.exists() or BSimServerInfo path validation before attempting to connect."],"exampleFix":"// before\nH2FileFunctionDatabase db = new H2FileFunctionDatabase(serverInfo);\ndb.initialize(); // throws if file missing\n\n// after\nPath dbPath = Paths.get(serverInfo.getDBName());\nif (!Files.exists(dbPath)) {\n    throw new IOException(\"BSim H2 database not found: \" + dbPath);\n}\nH2FileFunctionDatabase db = new H2FileFunctionDatabase(serverInfo);\ndb.initialize();","handlingStrategy":"validation","validationCode":"// Verify H2 database file exists before connecting\nPath dbPath = Paths.get(serverInfo.getDBName());\nif (!Files.exists(dbPath)) {\n    throw new FileNotFoundException(\n        \"BSim H2 database file does not exist: \" + dbPath);\n}","typeGuard":null,"tryCatchPattern":"try {\n    database.initialize();\n} catch (SQLException e) {\n    if (e.getMessage().startsWith(\"Database does not exist:\")) {\n        // Either create the database or correct the path\n        if (shouldCreate) {\n            database.createDatabase(config);\n        } else {\n            showErrorDialog(\"BSim Database Not Found\", e.getMessage());\n        }\n    }\n    throw e;\n}","preventionTips":["Always check file existence before opening an H2 BSim database.","Use absolute paths in BSim H2 URLs to avoid ambiguity.","Maintain a registry of created BSim databases to avoid referencing non-existent ones.","Provide a 'create if not exists' option in scripts that first checks, then generates."],"tags":["bsim","h2","database","file-not-found","sql"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}