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

446
Visualizações
Multiple mssql connections in Node.js

I want to have two MSSQL connections to two different databases in the same Node.js process. For some reason, only the first connection is successful for querying.

const sql = require('mssql');

(async () => {
    try {
        // First connection (success)
        const connection = await sql.connect('mssql://user:pass@10.x.x.x')
        // First connection (success)
        const connection2 = await sql.connect('mssql://user2:pass2@11.x.x.x')

        // Query in the first database -- success
        console.log(await connection.query(`
            select TOP(10) *
            from dbname.dbo.column
            where 1 = 1
        `))

        // Query in the second database
        //   Fails: Invalid object name 'Product
        //   Only if the first db connection is made.
        //   Succeeds if the first connection would be to this database
        console.log(await connection2.query(`
            SELECT TOP(10) * FROM Product
        `))
    } catch (err) {
        console.log(err)
    }
})()

Why is this? How can we solve this?

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