// SQLite error reference

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
Error message
unable to open database file

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

  1. Use an absolute path and make sure every directory in it exists.

  2. Check permissions on the file and its directory for the user the program runs as.

  3. If temporary files are the problem, point SQLite at a writable directory with the SQLITE_TMPDIR or TMPDIR environment variable, or keep temporary storage in memory.

    PRAGMA temp_store = MEMORY;
  4. In the sqlite3 shell, confirm what was opened.

    .databases

Related errors

More primary result codes errors

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.

// fewer errors, faster fixes

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.