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.
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:-
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.