Skip to content

Multiple Request On Multiple Connection #49

@npshubh

Description

@npshubh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions