- Result code
- SQLITE_NOTADB (26)
- Product
- SQLite library
- Versions
- SQLite 3.x (examples run on 3.39.2; shell output from 3.50.6)
- Category
- Files & Permissions
- Last reviewed
- 24 October 2026
On this page
What it means
This error means the file SQLite opened does not start with a valid SQLite database header, so it is a different kind of file, an encrypted database opened without the right key, or a file whose header was damaged.
Every SQLite 3 database starts with a 100-byte header whose first 16 bytes are the text SQLite format 3 followed by a zero byte. Opening a file does not read it, so the open succeeds and the error appears on the first statement that needs the database: a query on a table, sqlite_schema or a PRAGMA such as journal_mode. Statements that do not touch the file (SELECT 1, SELECT sqlite_version()) still work, which can make the connection look healthy. A zero-byte file is not an error: SQLite treats it as a new, empty database, so you get no such table instead.
SQLite reports this code when the header is missing or invalid, not when the content behind a valid header is damaged; that is database disk image is malformed. An encrypted database (SQLCipher, the SQLite Encryption Extension and similar) looks like random bytes without its key, so a plain SQLite build, or the right build with a wrong or missing key, reports the same error.
Common causes
- The path points to a different kind of file: a CSV export, a JSON or text file, a ZIP or backup archive, or a file saved with a .db or .sqlite extension that is not SQLite.
- A download or sync stored something else under the database name: an HTML error or login page, or a Git LFS pointer file when the repository was cloned without LFS.
- The database is encrypted and was opened without the key, with the wrong key, or with a library that has no encryption support.
- The first bytes of the file were overwritten, for example by a program that wrote to the wrong file or an incomplete copy.
Diagnose it
Read-only These statements only read the schema (sqlite_schema and read-only PRAGMA queries) or your own data. They do not change data, settings or the database file, so they are safe to run first.
Look at the first 16 bytes of the file
A real SQLite 3 database starts with 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 ("SQLite format 3" and a zero byte). On Linux or macOS run head -c 16 shop.db | xxd or file shop.db; in PowerShell 7, Format-Hex -Path shop.db -Count 16. Readable text such as id,name, <!DOCTYPE html> or version https://git-lfs tells you what the file really is; random-looking bytes suggest an encrypted database.
Confirm which file the connection opened
database_list does not read the database itself, so it works even on a file that is not SQLite.
PRAGMA database_list; The absolute path of the file. Make sure it is the database you meant to open, not a file with a similar name or an older copy.
Check a replacement file before you use it
Before switching to a backup or a fresh download, open it and run a quick check.
SELECT COUNT(*) AS objects FROM sqlite_schema;
PRAGMA quick_check; A count of tables, indexes and views, and ok from quick_check. If either statement fails with "file is not a database", that copy is not usable either.
How to fix it
Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.
Open the real database file
Client or network sideCorrect the path or file name in your configuration. If the file came from a download or a repository, fetch it again properly: check the HTTP status and content type before saving, and for Git LFS run git lfs pull.
Open an encrypted database with its library and key
Client or network sideUse the same encryption library the database was created with (for example an SQLCipher build of SQLite) and supply the key straight after opening, before any other statement, as that library documents. A plain SQLite library cannot read the file at all.
Import data that is in another format
Client or network sideIf the file is a CSV export, create a new database and import it, for example with the sqlite3 shell's .import --csv command (shown below; we ran it on 3.50.6). For JSON or SQL dump files, load them with your application or .read for a dump.
-- sqlite3 new_shop.db
.import --csv customers.csv customers
SELECT COUNT(*) FROM customers;
Restore the database from a backup
Changes database stateIf the header of the real database was overwritten, the most reliable fix is the last good backup. Stop the application, keep the damaged file aside (do not delete it), check the backup with the queries above, then put it in place. Never experiment on the only copy of the damaged file.
Examples
A CSV file opened as a database
-- shop.db is really a CSV export:
-- id,name
-- 1,Sara
SELECT * FROM customers;
file is not a database
Reproduced on SQLite 3.39.2, 24 October 2026.
A Git LFS pointer file instead of the database
-- shop.db was cloned without Git LFS, so it holds the pointer text:
-- version https://git-lfs.github.com/spec/v1
-- oid sha256:...
-- size 81920
PRAGMA journal_mode;
file is not a database
Reproduced on SQLite 3.39.2, 24 October 2026.
The header of a real database was overwritten
CREATE TABLE orders (id INTEGER PRIMARY KEY, total REAL);
INSERT INTO orders (total) VALUES (10);
-- then another program overwrites the first 16 bytes of shop.db
SELECT * FROM orders;
file is not a database
Reproduced on SQLite 3.39.2, 24 October 2026.
An encrypted database opened without the right key
Shown as documented in the SQLite documentation; not reproduced here, because the lab's SQLite build has no encryption extension. The SQLite Encryption Extension documentation says a wrong key gives SQLITE_NOTADB on first access, worded there as "file is encrypted or is not a database".
-- vault.db was created with an encryption extension;
-- it is opened with plain SQLite, or with the wrong key
SELECT * FROM accounts;
file is not a database
How to prevent it
Give database files a consistent extension and keep exports (CSV, JSON, dumps) under their own extensions, so a wrong file is not picked up by name. When an application downloads or syncs a database, write it to a temporary name, check the first 16 bytes or run a quick check, and only then rename it into place.
For encrypted databases, keep the key handling in one place and fail with a clear message when the key is missing. Keep regular backups made with VACUUM INTO or the backup API, because a checked backup is the dependable way back from a damaged file.
Common questions
How do I fix "file is not a database" in SQLite?
Check the first bytes of the file. If they do not read "SQLite format 3", it is another kind of file (CSV, HTML, a Git LFS pointer) or an encrypted database: open the right file, or use the encryption library and key. If it was a real database whose header was overwritten, restore it from a backup.
Why does the connection open but the first query fails?
Opening a file does not read it. SQLite reads the header when the first statement needs the database, so that is where the error appears. Statements such as SELECT 1 that do not use the file still succeed.
Is this the same as "database disk image is malformed"?
No. "file is not a database" means the header at the start of the file is missing or invalid. "database disk image is malformed" means the header is valid but pages inside the file are damaged; PRAGMA integrity_check and the recovery tools apply to that case.
Learn more on CodeWithSQL
Official documentation
- SQLite result and error codes (SQLITE_NOTADB)
- Database file format: the database header
- SQLite Encryption Extension: wrong keys
- sqlite3 shell: importing CSV files
Last technically reviewed 24 October 2026; examples and diagnostics run on SQLite 3.39.2 (PHP PDO_SQLITE) and the sqlite3 shell 3.50.6. Messages are the text the SQLite library itself returns (sqlite3_errmsg) for the versions shown.