title: Execute multiple statements before releasing connection oracledb module node.js
body: <p>UPDATE: code updated below (6-20-2016). I am still having trouble with having the async waterfall to finish, but when I add my callback to the function(err) part of .forEachOf function, it still gives me the error.</p>
  
  <p>I am trying to run multiple insert statements to insert each value from two arrays to an oracle database using the oracledb module for node.js. I tried using a for loop to use the iterator to go through each array in the next insert statement. I am new to node.js and have trouble understanding the callbacks which I think is just being called to early to release the connection. I am getting errors stating...</p>
  
  <pre><code>NJS-032: connection cannot be released because a database call is in progress
  </code></pre>
  
  <p>Here is the function code I am using. </p>
  
  <pre><code>  var doinsert2 = function (conn, cb) {
    //for(var i = 0; i&lt;headers.length; i++)
    async.forEachOf(headers, function (value, key, callback) 
    {
        conn.execute(
          "INSERT INTO " + db_extern_msg_prop + " VALUES ('" + unique_id + "','" + headers[key] + "',0,'" + values[key] + "')",
          //[unique_id, 'prop name test', 0, 'prop value test'],  // Bind values
          function(err, result)
          {
            if (err) {
              //return cb(err, conn);
              console.log("Error: " + err);
            } else {
              //console.log("SECOND INSERT : Rows inserted: " + result.rowsAffected);  // 1
              //return cb(null, conn);
            }
          });
          callback();
     },function (err) {
      //return cb(null, conn);    
     });
  
  };
  
  //used to order the functions to be processed. 
  //This keeps the connection first, and the same unique id for both tables.
  async.waterfall(
    [
      doconnect,
      doinsert1,
      doinsert2
    ],
    function (err, conn) {
      if (err) { console.error("In waterfall error cb: ", err, " "); }
      if (conn)
        dorelease(conn);
    });
  </code></pre>
  
  <p>All the records are being entered in fine but I want to better understand what I am missing. Also fairly new to stackoverflow so bear with me. Thanks in advance for help.</p>