n8n-io/n8n · error · NodeOperationError
Could not connect to database
Error message
Could not connect to database
What it means
Thrown by the sqlite3 driver's connection callback inside getSqliteDataSource when opening the temp .sqlite file fails. Note: the throw happens inside an async sqlite3 callback, so it will NOT propagate cleanly to the caller — this is a latent bug; the promise resolves and the failure surfaces later as a query error or undefined behavior.
Source
Thrown at packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/SqlAgent/other/handlers/sqlite.ts:40
const stream = await this.helpers.getBinaryStream(binaryData.id, chunkSize);
const buffer = await this.helpers.binaryToBuffer(stream);
fileBase64 = buffer.toString('base64');
} else {
fileBase64 = binaryData.data;
}
const bufferString = Buffer.from(fileBase64, BINARY_ENCODING);
// Track and cleanup temp files at exit
temp.track();
const tempDbPath = temp.path({ suffix: '.sqlite' });
fs.writeFileSync(tempDbPath, bufferString);
// Initialize a new SQLite database from the temp file
const tempDb = new sqlite3.Database(tempDbPath, (error: Error | null) => {
if (error) {
throw new NodeOperationError(this.getNode(), 'Could not connect to database');
}
});
tempDb.close();
return new DataSource({
type: 'sqlite',
database: tempDbPath,
});
}
View on GitHub (pinned to 5ac6606e81)
Solutions
- Verify the binary input is genuinely a SQLite database file (check the magic header 'SQLite format 3').
- If the data is CSV/JSON, convert it to SQLite first with a Code node or a dedicated converter.
- Ensure the n8n process has write access to the system temp directory.
Example fix
// before — non-SQLite binary reaches the agent
// (no validation; opaque downstream failure)
// after — validate the SQLite magic header before calling the agent
const b = items[0].binary?.data;
if (b) {
const buf = Buffer.from(await this.helpers.getBinaryDataBuffer(b.id));
if (buf.subarray(0, 15).toString('ascii') !== 'SQLite format 3\u0000') {
throw new NodeOperationError(this.getNode(), 'Input is not a valid SQLite file');
}
} Defensive patterns
Strategy: validation
Validate before calling
// Validate the SQLite magic header before the agent runs
const b = items[i].binary?.[binaryPropertyName];
if (b) {
const buf = b.id
? await this.helpers.binaryToBuffer(await this.helpers.getBinaryStream(b.id))
: Buffer.from(b.data, 'base64');
if (buf.subarray(0, 15).toString('ascii') !== 'SQLite format 3\u0000') {
throw new NodeOperationError(this.getNode(), 'Input binary is not a valid SQLite database file');
}
} Type guard
function isSqliteBuffer(buf: Buffer): boolean {
return buf.subarray(0, 15).toString('ascii') === 'SQLite format 3\u0000';
} Prevention
- Verify the upstream node outputs a genuine .sqlite file (check magic header).
- Convert CSV/JSON to SQLite upstream if needed.
- Be aware the current callback-based throw is a latent bug — surface validation upstream to avoid opaque failures.
When it happens
Trigger: The decoded base64 buffer is not a valid SQLite database file; the temp path is unwritable; the file is locked or truncated.
Common situations: Upstream node delivered a non-SQLite binary (e.g. a CSV, JSON, or corrupt blob) but the workflow expects .sqlite; the file was partially downloaded; disk-full or permissions issue on the temp directory.
Related errors
- No binary data found, please connect a binary to the input i
- No binary data received.
- The ‘prompt’ parameter is empty.
- No data source found, please configure data source
- SQL operation "${blockedKeyword}" is not allowed
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/6b5128b49ae58778.
Report an issue: GitHub.