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

前端 未结 6 1569
暗喜
暗喜 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:12

    You have to create a poolConnection try this:

    new sql.ConnectionPool(config).connect().then(pool => {
    
      return pool.request().query("SELECT * FROM MyTable")
    
      }).then(result => {
    
        let rows = result.recordset
        res.setHeader('Access-Control-Allow-Origin', '*')
        res.status(200).json(rows);
        sql.close();
    
      }).catch(err => {
    
        res.status(500).send({ message: `${err}`})
        sql.close();
    
      });
    

提交回复
热议问题