Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

445
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!