title: Why am I getting node-sqlite3 SQLITE_BUSY
body: <p>I have a problem with a webserver that stores data periodically in a node-sqlite3 driven database. It will work fine a few times and then just fails with </p>
  
  <blockquote>
    <p>SQLITE_BUSY: database is locked</p>
  </blockquote>
  
  <p>Sometimes all inserts are not completed to the database even when not failing, leaving only a portion of the inserts in the table.</p>
  
  <pre><code>setInterval(doInserts,60000);
  
  doInserts() {
  calculateData(function(data){
      if(data)
      {
          insertData(data);
      }
  });
  }
  
  function insertData(data) {
  var sqlite3 = require("sqlite3").verbose();
  
  //user fs existSync to check if file exists and openSync(file,'w') to create if not
  
  db.serialize(function(){
      var stmt = db.prepare("INSERT INTO mytable (col1,col2) values (?,?)");
  
      for(var i =0;i&lt;data.length;i++)
          stmt.run(data[0],data[1]);
      stmt.finalize();
  });
  db.close();
  }
  </code></pre>
  
  <p>Taking account I am new to both node and SQLite, I'm guessing that I am using something in the wrong way, causing multiple open threads or processes to lock up the db, but no documentation or research has gotten me any closer to a solution.</p>