node.js mssql:错误:全局连接已存在。首先调用sql.close()

时间:2019-02-20 16:27:06

标签: node.js sql-server

我有以下基于this文档的代码:

(async () => {
  try {
    const pool = await mssql.connect(source.connstring);
    const result = await pool.request().query(source.query);
    console.dir(result);
    pool.close(); // also tried with mssql.close();
  } catch (err) {
    if (pool) pool.close();
    console.log(err);
  }
})();

第一次运行正常,第二次(使用不同的source.connstring)则出现以下错误:

Error: Global connection already exists. Call sql.close() first.
    at Object.connect ([...]my_project\db_crawler\node_modules\mssql\lib\base.js:1636:31)
    at [...]my_project\db_crawler\db_crawler.ts:92:58
    at step ([...]my_project\db_crawler\db_crawler.ts:33:23)
    at Object.next ([...]my_project\db_crawler\db_crawler.ts:14:53)
    at [...]my_project\db_crawler\db_crawler.ts:8:71
    at new Promise (<anonymous>)
    at __awaiter ([...]my_project\db_crawler\db_crawler.ts:4:12)
    at [...]my_project\db_crawler\db_crawler.ts:86:27
    at readFromSource ([...]my_project\db_crawler\db_crawler.ts:110:11)
    at [...]my_project\db_crawler\db_crawler.ts:62:57

我发现了两个类似的问题,但我似乎无法解决。

0 个答案:

没有答案