Request Insert in for loop

119 views
Skip to first unread message

Tristan Sinoquet

unread,
Jun 9, 2017, 10:37:42 AM6/9/17
to tedious
Hey,

First time, I am sorry for my english.
So I have a project with SQLserver and I use Tedious. But the problem is that Itry to insert more than 1000 rows. So I try with bulk but I failed and I try too one row by row with the insert. With this two case I have diffrents error sorry I don't catch the with bulk but my second error is :
{ RequestError: Requests can only be made in the LoggedIn state, not the SentClientRequest state
   at RequestError (D:\Projet_Cegid\node_modules\tedious\lib\errors.js:34:12)
   at Connection.makeRequest (D:\Projet_Cegid\node_modules\tedious\lib\connection.js:1108:33)
   at Connection.execSql (D:\Projet_Cegid\node_modules\tedious\lib\connection.js:898:19)
   at insertIntoDatabase (D:\Projet_Cegid\server.js:287:17)
   at D:\Projet_Cegid\server.js:230:41
   at D:\Projet_Cegid\node_modules\soap\lib\client.js:180:7
   at finish (D:\Projet_Cegid\node_modules\soap\lib\client.js:411:5)
   at parseSync (D:\Projet_Cegid\node_modules\soap\lib\client.js:373:12)
   at D:\Projet_Cegid\node_modules\soap\lib\client.js:349:14
   at Request._callback (D:\Projet_Cegid\node_modules\soap\lib\http.js:118:5)
 message: 'Requests can only be made in the LoggedIn state, not the SentClientRequest state',
 code: 'EINVALIDSTATE' }


and my function that I call in the loop :

function insertIntoDatabase(k, dateLecture, numDossier, user, bulletins, periodePaie){
    console.log("Inserting a brand new product into database...");
    request = new Request(
        "INSERT INTO Extraction (Id, DateLecture, NumDossier, Utilisateur, Quantite, PeriodePaie, Type) VALUES ("+k+", "+dateLecture+", "+numDossier+", '"+user+"', "+bulletins+", '"+periodePaie+"', 'bulletins')",
        function(err, rowCount, rows) {
            console.log(err)
            console.log(rowCount + ' row(s) inserted');
        }
    );
    connections.execSql(request);
}


Thinks for your reply 
Reply all
Reply to author
Forward
0 new messages