1

After I run the code, all I get is the console log "Done.", with nothing updated in the database. What am I doing wrong?

var pool = new sql.ConnectionPool(config);
var ps = new sql.PreparedStatement(pool);

ps.input('code', sql.VarChar);
ps.input('hex', sql.VarChar);

ps.prepare("UPDATE tHE_SetItem SET acPicture = CONVERT(varbinary(max), @hex, 2) WHERE acIdent = @code;", function(err) {

    async.mapSeries(hexes, function(pair, next) {

        ps.execute({code: pair.code, hex: pair.hex}, next);

    }, function(err) {

        ps.unprepare(function(err) {

            console.log("Done!");

        });
    });
});
3
  • 1
    Have you tried logging err? Clearly the error callback seems to be executing so it would make sense to try that. Commented Sep 5, 2017 at 8:07
  • @Script47 Damn... You are right. This is what you get for working 12 hours straight. Simple things pass you by. Thank you for the slap to the head. This lead me to realize that I am not actually connecting with pool.connect() Commented Sep 5, 2017 at 10:49
  • 2
    Eh, take a break, work is not that important. Commented Sep 5, 2017 at 11:00

1 Answer 1

1

As pointed out in the comment, I left out the error callbacks, which in turn notified me that I was not actually making a connection. Here is the revised code.

var pool = new sql.ConnectionPool(config);
pool.connect().then(function(){ // <------------- This in particular
    var i = 0;
    var ps = new sql.PreparedStatement(pool);
    ps.input('code', sql.VarChar);
    ps.input('hex', sql.VarChar);
    ps.prepare("UPDATE tHE_SetItem SET acPicture = CONVERT(varbinary(max), @hex, 2) WHERE acIdent = @code;", function(err) {
        if(err) console.log(err);
        async.mapSeries(hexes, function(pair, next) {
            i++;
            console.log(i + "/" + hexes.length + " " + Math.round(i / hexes.length * 100) + "% - " + pair.code);
            ps.execute({code: pair.code, hex: pair.hex}, next);
        }, function(err) {
            if(err) console.log(err);
            ps.unprepare(function(err) {
                if(err) console.log(err);
                console.log("Done!");
            });
        });
    });
}).catch(function (err) {
    console.log(err);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.