1

This code results in "Connection not yet open." error. The pool is connected and available for the first select where I am getting records to update.

After I process my data I have an array of UPDATE statements. Then the inline async function runs and results in the error above.

I have also attempted to run multiple UPDATE statements with a single query. This results in an UNKNOWN error unless the query updates array has only a single array member.

This is running against SQL Server 2000.

const doQuery = async (pool, sqlStr) => {
    return await pool.request().query(sqlStr);
};

const updateResidental = async args => {
    let toUpdateSql = `SELECT * FROM blah WHERE blah=blah)`;
    const toUpdate = (await doQuery(args.pool, toUpdateSql)).recordset;

    const sqlStrings = ['UPDATE blah1;','UPDATE blah2;','UPDATE blah3;'];

    (async pool => {
        return await Promise.all(sqlStrings.map(async sqlStr => {
            return await doQuery(pool, sqlStr);
        })).then(results => {
            console.log(results);
        }).catch(err => {
            console.log(err)
        });
    })(args.pool);
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jeff Greer
  • 113
  • 7

0 Answers0