{"record":{"id":"1c2276a54020f8e8","repo":"NationalSecurityAgency/ghidra","slug":"could-not-create-database-1c2276","errorCode":null,"errorMessage":"Could not create database: {}","messagePattern":"Could not create database: (.+?)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/file/H2FileFunctionDatabase.java","lineNumber":120,"sourceCode":"\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 {\n\t\ttry {\n\t\t\tsuper.createDatabase(config);\n\n\t\t\tConnection db = initConnection();\n\t\t\ttry (Statement st = db.createStatement()) {\n\t\t\t\tvectorTable.create(st);\n\t\t\t}\n\t\t}\n\t\tcatch (final SQLException err) {\n\t\t\tthrow new SQLException(\"Could not create database: \" + err.getMessage());\n\t\t}\n\t}\n\n\t@Override\n\tprotected void dropDatabase() throws SQLException {\n\n\t\tif (getStatus() == Status.Busy || fileDs.getActiveConnections() != 0) {\n\t\t\tthrow new SQLException(\"database in use\");\n\t\t}\n\n\t\tclose(); // close this instance\n\n\t\tif (!fileDs.exists()) {\n\t\t\t// ignore request and return\n\t\t\treturn;\n\t\t}\n\n\t\t// Connect to database and examine schema","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/file/H2FileFunctionDatabase.java#L102-L138","documentation":"Thrown as an SQLException by H2FileFunctionDatabase.createDatabase() wrapping any SQLException from the parent class's createDatabase, the subsequent initConnection, or the vector table creation. It re-throws with a 'Could not create database' prefix and the original error message, making it clear that the database creation pipeline failed at some internal step.","triggerScenarios":"Occurs when super.createDatabase(config) fails (schema setup, metadata insertion), initConnection() fails (file system permission issue, disk full), or vectorTable.create(st) fails (DDL error, H2 driver issue). The underlying SQLException could be from any of these steps during the create flow.","commonSituations":"Insufficient disk space or file system permissions for the target directory. H2 JDBC driver version incompatibility. Corrupted BSim configuration passed to createDatabase. Concurrent creation attempts on the same file. The parent schema creation encounters a constraint or type error.","solutions":["Read the wrapped message after 'Could not create database: ' to find the specific SQL error (e.g., permission denied, disk full, duplicate key).","Verify write permissions and available disk space at the target database file path.","Ensure no other process is using the H2 file during creation.","Check H2 driver compatibility with the Ghidra version.","If the error is in vectorTable.create, inspect the DDL and H2 version support for SERIAL/CLOB types."],"exampleFix":"// before\ntry {\n    db.createDatabase(config);\n} catch (SQLException e) {\n    // opaque error\n}\n\n// after\ntry {\n    db.createDatabase(config);\n} catch (SQLException e) {\n    String detail = e.getMessage();\n    if (detail.contains(\"Could not create database:\")) {\n        String rootCause = detail.substring(detail.indexOf(':') + 1).trim();\n        Msg.showError(this, null, \"BSim Create Failed\",\n            \"Database creation error: \" + rootCause);\n    }\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Pre-flight checks before database creation\nPath dir = dbPath.getParent();\nif (!Files.isWritable(dir)) {\n    throw new IllegalStateException(\n        \"Cannot write to database directory: \" + dir);\n}\nif (dir.toFile().getUsableSpace() < MIN_REQUIRED_SPACE) {\n    throw new IllegalStateException(\"Insufficient disk space for database creation\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    database.createDatabase(config);\n} catch (SQLException e) {\n    String msg = e.getMessage();\n    if (msg.startsWith(\"Could not create database:\")) {\n        String rootCause = msg.substring(msg.indexOf(':') + 1).trim();\n        Msg.showError(this, null, \"BSim Database Creation Failed\",\n            \"Root cause: \" + rootCause);\n    }\n    throw e;\n}","preventionTips":["Verify write permissions and disk space before calling createDatabase().","Ensure no other process has the target H2 file open during creation.","Use a compatible H2 JDBC driver version matched to Ghidra.","Log the wrapped SQLException message to identify the exact creation step that failed."],"tags":["bsim","h2","database","creation","sql"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}