Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Request On Multiple Connection #49

Open
npshubh opened this issue Mar 7, 2018 · 1 comment
Open

Multiple Request On Multiple Connection #49

npshubh opened this issue Mar 7, 2018 · 1 comment

Comments

@npshubh
Copy link

npshubh commented Mar 7, 2018

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.

@arthurschreiber
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants