// SQLite error reference

SQLITE_MISUSE: bad parameter or other API misuse

The program called an SQLite function in an undefined way, such as using a statement after finalizing it. It is a bug in the calling code.

Result code
SQLITE_MISUSE
Name
21
Category
Primary result codes
Error message
bad parameter or other API misuse

What it means

SQLITE_MISUSE (21) means the application used the SQLite API incorrectly. SQLite tries to detect misuse but, as its documentation stresses, detection is not guaranteed, so the same bug can also crash or corrupt memory. Any SQLITE_MISUSE is a bug to fix, not a condition to handle.

Common causes

  • Using a prepared statement after sqlite3_finalize(), or a connection after sqlite3_close().
  • Sharing one connection or statement between threads without the serialized threading mode.
  • Calling sqlite3_step() again after it returned an error without resetting the statement.
  • Passing a NULL or invalid connection handle.

How to fix it

  1. Find the call that returned the code and check the object's life cycle: prepare, bind, step, reset or finalize, and never use it after finalizing.

  2. Give each thread its own connection, or open connections in serialized mode, and don't share statements across threads.

  3. In higher-level bindings, look for objects used after their connection was closed, for example a cursor kept after close().

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.