Below is the code i am using ,Some times it does not enter .then (function() ,Please let me know how to close the existing connection , I have tried various options like conn.close() after connecting, but it still dint work.
var sql = require("C:/Protractor_Scripts/node_modules/mssql");
function getEmp() {
    console.log('results'); 
    var conn = new sql.Connection("Server=, 1433;Database=;User Id=;Password=;Encrypt=true");
    console.log(conn); 
    console.log(conn.connect());
    conn.connect().then(function () { 
        console.log(conn.connect()); 
        var req = new sql.Request(conn); 
        req.query("select * from").then(function (recordset) {
            console.log(recordset);   
            conn.close();
        }).catch(function (err) {
            console.log(err);   
            conn.close();
        }); 
    }).catch(function (err) {
        console.log(err);  
    });
}
getEmp();
Below is the full error message
[ConnectionError: Already connecting to database! Call close before connecting to different database.]
  name: 'ConnectionError',
message: 'Already connecting to database! Call close before connecting to different database.',
  code: 'EALREADYCONNECTING' }
                Try removing multiple conn.connect() calls and have only one call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With