Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

193
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda