title: SQLite C++ 'database is locked' when multiple processes access db in readonly mode
body: <p>I have an sqlite database that <strong>doesn't change</strong>.</p>
  
  <p><strong>Multiple</strong> processes that open a database connection each in <strong>SQLITE_OPEN_READONLY</strong> mode using sqlite3_open_v2. Each process is single threaded</p>
  
  <p>The connections are made from an MSVC project using the official <a href="https://www.sqlite.org/capi3ref.html" rel="noreferrer">C/C++ Interface</a>'s single amalgamated C source file.</p>
  
  <p>According to the SQLite FAQ <a href="http://www.sqlite.org/faq.html#q5" rel="noreferrer">multiple processes running SELECTs is fine</a></p>
  
  <p>Each process after opening the database creates 4 prepared <strong>SELECT</strong> statements each with 2 bindable values.</p>
  
  <p>Over the course of the execution the statements (one at a time) have the following called on them repeatedly as required</p>
  
  <ul>
  <li>sqlite3_bind_int</li>
  <li>sqlite3_bind_int</li>
  <li>sqlite3_step (while SQLITE_ROW is returned)</li>
  <li>sqlite3_column_int (while there was a row)</li>
  <li>sqlite3_reset</li>
  </ul>
  
  <p>The prepared statements are reused so finalize isn't called on each of them until near the end of the program. Finally the database is closed at the very end of execution.</p>
  
  <p><strong>The problem is</strong> any of these operations can fail with <strong>error code = 5: 'database is locked'</strong></p>
  
  <p>Error code 5 is <a href="https://www.sqlite.org/rescode.html#busy" rel="noreferrer">SQLITE_BUSY</a>  and the website states that </p>
  
  <blockquote>
    <p>"indicates a conflict with a separate database connection, probably in a separate process"</p>
  </blockquote>
  
  <p>The rest of the internet seems to agree that multiple READONLY connections is fine. I've gone over and over the source and can't see that anything is wrong (I can't post it here sadly, I know, not helpful)</p>
  
  <p>So I'm turning it to you guys, what could I possibly be missing?</p>
  
  <p><strong>EDIT 1</strong>:
  Database is on a local drive, File system is NTFS, OS is Windows 7.</p>
  
  <p><strong>EDIT 2</strong>:
  Wrapping all sqlite3 calls in infinite loops that check if SQLITE_BUSY was returned and then remake the call alleviates the problem. I don't consider this a fix but if that truly is the right thing to do then I'll do that.</p>