Y
Y
YuyukoSaigeji2018-02-19 12:14:29
Node.js
YuyukoSaigeji, 2018-02-19 12:14:29

How to create two connections to different sql server in node.js?

I create a connection in this way
var mssql = require('mssql');
var pool1 = mssql.connect(config1, err => {
console.log(err);
});
var pool2 = mssql.connect(config2, err => {
console.log(err);
});
To which I get the error Global connection already exists
It turns out it is impossible to create two connections at the same time, without closing the previous one

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
YuyukoSaigeji, 2018-02-19
@YuyukoSaigeji

Figured it out myself. Instead of connect, you need to use ConnectionPool(config).connect(err => {}). Apparently connect creates a pool and sets it as global, and if the global pool is already set, it throws an exception.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question