我正在使用节点 js 的 mssql 包,每条路由我都在创建一个新连接并执行事务,当我从客户端并行调用两个 api 时,mssql 抛出“连接已关闭”
示例:当此 api 同时调用时,“连接已关闭”即将出现
router.get('/', async function (req, res, next) {
let result = {};
try {
let pool = await sql.connect(db);
try {
let sqlResponse = await pool.request().execute('p_getAllData');
result = {
status: true,
data: sqlResponse.recordsets[0]
}
pool.close();
} catch (e) {
pool.close();
throw e;
}
} catch (e) {
result = {
status: false,
data: e.message
}
console.log(e);
}
res.send(result);
});