The sqlite3_prepare() interface has to read the database schema upon first use, or after a schema change. Perhaps some other connection is modifying the database at the same moment. Suggestions: * Set [WAL mode](https://www.sqlite.org/wal.html) using [PRAGMA journal_mode=WAL](https://www.sqlite.org/pragma.html#pragma_journal_mode). You only have to do this once per database, as the setting is sticky. This will probably be sufficient to solve your problem. * Set a busy timeout using [PRAGMA busy_timeout](https://www.sqlite.org/pragma.html#pragma_busy_timeout). This will cause SQLite to wait and retry (if it can) when it encounters a lock, rather than giving up immediately.