tediousjs/tedious-connection-pool

Multiple Request On Multiple Connection

npshubh opened this issue · 1 comments

I'm trying to insert 100 records in the database. But unfortunately, I get my request object updated with the last value in the loop. Is there any way by which I can send my every request with the current value given by the loop?

This is my code I'm using to acquire connection pool and request:-

function insertData(values) {
let procValue = { columns: 
   [ { name: 'SyncLogID', type: [Object], nullable: true },
     { name: 'RequestID', type: [Object], nullable: true, length: 255 }],
  rows: 
   [ [values.SyncLogID, values.RequestID  ] ] };

pool.acquire(function(err, connection) {
        if (err) {
          return reject(err);
        }
        let request = new Request("userStoredProcedure", function(err, rowCount, rows) {
          if (err) {
            return reject(err);
          } else {
            connection.release();
            return resolve(rows);
          }
        });
        request.addParameter("userDefinedDataType", TYPES.TVP, procValue);
        connection.callProcedure(request);
      });
}

Now notice that the function is called in a loop and the parameter "values" keeps changing. But the problem arises when "connection.callProcedure(request)" intakes the last updated value from the loop and keeps inserting the same last value till the loop count.

Are you changing the procValues object during loop iteration? If so, that might explain the issue you are seeing. 🤔 the code snippet you posted can not really be used to debug or reproduce your issue. Would you mind providing an example that can be executed?