SQLITE_CANTOPEN: unable to open database file
SQLite couldn't open the database file or one of its temporary files: a wrong path, a missing directory, a permissions problem, or a path that is a directory.
- Result code
SQLITE_CANTOPEN- Name
14- Category
- Primary result codes
What it means
SQLITE_CANTOPEN (14) means the operating system refused to open a file SQLite needed. That is usually the main database file, but it can also be a temporary file. SQLite creates a new database file when the path doesn't exist, so this error usually means the directory is missing or not writable, not that the file is missing.
Extended codes narrow it down, for example SQLITE_CANTOPEN_ISDIR (the path is a directory) and SQLITE_CANTOPEN_FULLPATH (the full path couldn't be resolved).
Common causes
- The directory in the path doesn't exist; SQLite creates files, not directories.
- A relative path resolved against an unexpected working directory, for example in a service or a test runner.
- No permission to read the file, or to create it in that directory.
- The path points at a directory (
SQLITE_CANTOPEN_ISDIR). - The temporary directory is missing or not writable, so a temporary file can't be created.
- Too many open files in the process.
How to fix it
-
Use an absolute path and make sure every directory in it exists.
-
Check permissions on the file and its directory for the user the program runs as.
-
If temporary files are the problem, point SQLite at a writable directory with the
SQLITE_TMPDIRorTMPDIRenvironment variable, or keep temporary storage in memory.PRAGMA temp_store = MEMORY;
-
In the
sqlite3shell, confirm what was opened..databases
Related errors
SQLITE_READONLYattempt to write a readonly databaseSQLITE_PERMaccess permission deniedSQLITE_NOTADBfile is not a databaseSQLITE_CANTOPEN_ISDIRthe path is a directory
More primary result codes errors
SQLITE_ERRORSQL logic errorSQLITE_ABORTquery abortedSQLITE_BUSYdatabase is lockedSQLITE_LOCKEDdatabase table is lockedSQLITE_NOMEMout of memorySQLITE_INTERRUPTinterruptedSQLITE_IOERRdisk I/O errorSQLITE_CORRUPTdatabase disk image is malformed
The code and message text are from the SQLite result and error codes documentation. Browse the full SQLite error list or search every database error.
Work on SQLite in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQLite and the other databases you use.