Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
mssql execute: return both promise and recordsets

I am using node-mssql to perform a bunch of operations inside a transaction. Spcifically, the methods used in order are begin tran,bulk,bulk,exec,commit. Here is part of the code, which works as-is:

// bulk insert #columns
.then(result => {  
    const request=new sql.Request(globalTx);
    const tableObj = new sql.Table('#columns');  //#columns
    /* some code to build the desired tableObj*/
    return request.bulk(tableObj);
})

// exec proc
.then(result => { 
    returnObject.lastSuccessfulStep='bulk #data'
    returnObject["#columns rows"]=result.rowsAffected
    const request=new sql.Request(globalTx);
    /* some code to build the desired proc call*/
    return request.execute('spc_sqlDMLCommand');
})

//commit
.then(result => { 
    return globalTx.commit(); // returns promise
})

So you can see the use of chained .thens. There is a catch() at the end.

My problem is that in the case od the execute method, while the then() /catch() promise structure feels friendly to me, I also need the information that the method returns through its callback. Citing the reference about the second parameter:

callback(err, recordsets, returnValue) - A callback which is called after execution has completed, or an error has occurred. returnValue is also accessible as property of recordsets. Optional. If omitted, returns Promise.

Is there a way to save err/recordsets/returnValue to some objects while still maintaining the flow, ie not having to cut-paste the subsequent then()s into the execute's callback?

Solution attempt:

I tried using a callback:

request.execute('spc_sqlDMLCommand',function cb(a,b,c){
    console.log('a:\n',a,'b:\n',b,'c:\n',c)
});

but I got this error:

message: 'Requests can only be made in the LoggedIn state, not the SentClientRequest state', code: 'EINVALIDSTATE'

Following this up on the internet, it seems to be about multiple queries having problems. But, it already works for me if I do it in the way mentioned above...

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda