2

I have a code block that where there are two await statements. The very first time the server is running I believe it is blowing right by the await SQL.connect. After there's been a couple of calls (allowing for time for connection) through this then the procedure works fine.

This is for NodeJS, MSSQL package.

Why is my first await, not waiting?

    async execStoredProc(spDescriptor: StoredProcedureDescriptor) {
    if (!this.pool) {
        if (this.isFirst) {
            this.isFirst = false ;
        } else {
            SQL.close();
        }
        this.pool = await SQL.connect(this.config);
    }

    try {
        const request = new SQL.Request(this.pool) ;

        spDescriptor.parms.forEach(function(sqlParm: SqlParm){
            request.input(sqlParm.name, sqlParm.sqlType, sqlParm.value) ;
        })

        const qryresult = await request.execute(spDescriptor.storedProcedureName)

        let result = {} ;
        if (spDescriptor.multipleResultSets) {
            result = qryresult.recordsets ;
        } else {
            result = qryresult.recordset ;
        }
        return result ;
    } catch (err) {
        console.log("SQL Error===>", err);
        return [] ;
    }
}
jeff
  • 3,269
  • 3
  • 28
  • 45

0 Answers0