node.js Global connection already exists. Call sql.close() first

前端 未结 6 1575
暗喜
暗喜 2021-01-03 23:09

I\'m trying to create web services using node.js from an sql server database,in the frontend when i call those 2 webservices simultaneously it throws an error Global connect

6条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-04 00:00

    From the documentation, close method should be used on the connection, and not on the required module,

    So should be used like

    var connection = new sql.Connection({
    user: '...',
    password: '...',
    server: 'localhost',
    database: '...'
    });
    connection.close().
    

    Also couple of suggestions,
    1. putting res.send in a loop isn't a good idea, You could reply back the entire recordsets or do operations over it, store the resultant in a variable and send that back.
    2. Try using promises, instead of callbacks, it would make the flow neater

提交回复
热议问题