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

316
Vistas
mssql - uncaughtException in Stream Mode

I'm facing the same issue as mentioned here:

When trying to use stream and query a table without mentioning the schema.

Something like select * from table instead of select * from schema_name.table. I get the following error: mssql uncaughtException RequestError: Invalid object name

I was able to log the error while listening to readStream.on('error') but it still throws an uncaughtException.

Software versions

"mssql": "^7.2.1",
"nodejs":  "12.15.0"

Expected behavior:

Should be able to catch the uncaughtException

Actual behavior:

INFO: waaaaaa1
uncaughtException RequestError: Invalid object name 'employee'.
at handleError (.../node_modules/mssql/lib/tedious/request.js:388:15)
at Connection.emit (events.js:223:5)
at Connection.emit (.../node_modules/tedious/lib/connection.js:1071:18)
at Parser. (.../node_modules/tedious/lib/connection.js:1176:12)
at Parser.emit (events.js:223:5)
at Readable. (.../node_modules/tedious/lib/token/token-stream-parser.js:27:14)

Configuration:

    import mssql from 'mssql';
       try {
    mssql.connect({
      server,
      port: Number.parseInt(port),
      database,
      user,
      password,
      options: {
        encrypt: true, // for azure
        trustServerCertificate: trustServerCertificate ? true : false // change to true for local dev / self-signed certs
      }
    })
      .then(async client => {
        const readStream = client.request();
        readStream.stream = true;
        const passThroughStream = new stream.PassThrough();
        const writeStream = fs.createWriteStream(path.join(__dirname, './writeMe.json'));
      
        readStream.on('error', () => log.info('waaaaaa1'));
        passThroughStream.on('error', () => log.info('waaaaaa2'));
        writeStream.on('error', () => log.info('waaaaaa3'));

        readStream.pipe(passThroughStream).pipe(writeStream);
        readStream.query(query);
      })
      // the promise error handler
      .catch(() => {
        log.info('waaaaaa4');
      });

    // the main sql error handler:
    mssql.on('error', error => {
      log.error('SQL error1', error);
    });

    // the main sql error handler:
    client.on('error', error => {
      log.error('SQL error2', error);
    });


  }
  catch (err) {
    log.info('catchhhh meee', err);
  }
  finally {
    if(client){
      client.close();
    }
  }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Finally resolved the issue using const readableStream = request.toReadableStream();

Full code:

const request = client.request();
const readableStream = request.toReadableStream();
const writeStream = fs.createWriteStream(path.join(__dirname, './writeMe.json'));
const passThroughStream = new stream.PassThrough();
readableStream.on('end', () => passThroughStream.end());
readableStream.on('error', (e) => log.info('waaaaaa1'));
readableStream.pipe(passThroughStream).pipe(writeStream);
request.query(query);
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try adding a catch handler to connect and more important to the mssql object as mentioned in the docs

mssql.connect({
   // ...
    
 })
.then(() => {
    return readStream.query(query);
})

// the promise error handler
.catch(() => {
    
})

// the main sql error handler:
mssql.on('error', error => {
    console.error('SQL error')
})
about 4 years ago · Juan Pablo Isaza Denunciar
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