The SQLite error file is not a database (result code SQLITE_NOTADB, error 26) appears when SQLite cannot recognize the file as one of its own databases. This is different from the database disk image is malformed error (SQLITE_CORRUPT, error 11), which means the file has a valid header but its internal structure is damaged. The file is not a database error has several distinct causes: the file may use encryption, it may be a different type of file entirely, or its header bytes may be missing or overwritten. Understanding the root cause is the first step toward recovery.
What the Error Means
Every SQLite database file begins with a 16-byte header: the ASCII string SQLite format 3 followed by a zero byte. When you open a file and SQLite does not find this exact header, it returns the SQLITE_NOTADB error. Older versions of SQLite displayed the message file is encrypted or is not a database, which is the same error. The header is stored on page 1 of the database, which also holds the schema. If page 1 is missing or overwritten, the error appears.
Common Causes of the NOTADB Error
The error can arise from several situations. Each cause requires a different approach.
- Encrypted database. Databases secured with SQLCipher do not start with the standard SQLite header. When you try to open such a file without providing the key, you get the sqlcipher file is not a database error (which is the same NOTADB result).
- Wrong file type. A file that is actually something else, such as a backup archive, an HTML file downloaded from a website, or a zero-filled placeholder, will not have the correct header.
- Damaged or missing header. If the first page of the database is overwritten or zero filled, the header and schema are destroyed. This can happen due to a partial write, a disk error, or accidental overwriting.
- File renamed without conversion. Renaming a file to have a .db or .sqlite extension does not change its content. If the original file was never a SQLite database, you will still see the error.
Diagnosing the Cause
Before attempting a fix, determine what kind of file you are dealing with. Use a hex editor or a command-line tool to inspect the first few bytes of the file. If the first bytes are the hex representation of SQLite format 3 followed by a zero, then the header is intact and the error may be caused by something else. If the header is missing, the file may be encrypted, a different format, or damaged.
Check for Encryption
If the file does not start with the SQLite header but begins with a different sequence of bytes (for example, the SQLCipher header is typically the same but with a different page size or salt), you may be dealing with a locked database. Without the correct key, you cannot open it. The error sqlite_notadb will persist even if the file is otherwise intact.
Check the File Type
Use the file command on Unix-like systems or inspect the file extension and contents. Common false positives include ZIP archives, SQL dump scripts, or plain text files. If the file is not a database, locate the correct file or reacquire it from a backup.
Fixing the Error
The fix depends on the cause. Below are procedures for each scenario.
If the File Is Encrypted
An encrypted database cannot be opened without the key. If you have the key, use the appropriate tool (such as SQLCipher with the key) to open the file. Repair tools that rebuild structure from readable pages cannot decrypt a locked database. Lost the key? There is no way to recover the data.
If the File Is the Wrong Type
Obtain the correct SQLite database file. If you mistakenly downloaded a webpage instead of the database, re-download the actual file. If you renamed a backup archive, restore the original file and extract it properly.
If the Header Is Damaged
When only the header and schema on page 1 are damaged but the rest of the database pages are intact, a repair tool can rebuild the structure from the readable pages. The process involves:
- Making a copy of the damaged file to work on.
- Using a tool that scans the file for intact pages and reconstructs the schema and data.
- Exporting the recovered data to a new, clean SQLite database.
This approach works only if the underlying data pages are not also corrupted. If the file is zero filled or overwritten completely, recovery is unlikely.
Preventing the Error
To avoid encountering file is not a database in the future, follow these practices:
- Always back up your SQLite databases before making changes.
- Use proper database tools to open and manipulate files, not general-purpose text editors.
- If you use encryption, store the key securely and separately from the database file.
- Verify downloads of database files by checking the file size and header before using them.
When to Use a Repair Tool
If the file has a valid SQLite header but still shows errors, you are dealing with a different problem (SQLITE_CORRUPT). For the NOTADB error, a repair tool is only useful when the header is damaged but the data pages are still present. Online services like sqlite.repair can attempt to recover data from such files by rebuilding the database structure from readable pages. No tool can decrypt a locked database or recover data from a file that was never a SQLite database.