我正在尝试使用NodeJS中的mssql包从MSSQL数据库获取查询。运行代码时,出现错误。还有一个问题是该错误仅出现在生产中,在开发中可以正常工作! :(
这是我的代码
const { Router } = require('express');
const { config } = require("../database/config");
const sql = require("mssql");
router.post("/", (req, res) => {
const {data1, data2} = req.body
const query = `The Query is too long but it works!`
switch (data1) {
case 'subdata1':
// Making the connection to MMSQL
const pool1 = new sql.ConnectionPool(Config);
const poolConnect = await pool1.connect() // The trace error indicates that the problem is in this line
// ^^^ exactly here
async function data1Path() {
await poolConnect;
try {
const request = await pool1.request();
const result = await request.query(query);
// Handling the query result
return result.recordset[0].Direccion.replace(/\\/g, "/");
} catch (error) {
console.log("SQL Error: ", error);
};
};
const getData1Query = await data1Path(); // Getting the path to find the file
}
case 'subdata2':
// doing another things...
})
下一个代码是我的数据库配置文件,我正在使用module.exports导出它:
const config = {
server: DB_HOST,
port: 1433,
user: DB_USER,
password: DB_PASSWORD,
database: "my_db_name",
connectionTimeout: 180000,
driver: "tedious",
stream: "true",
options: {
appName: APP_NAME,
encrypt: false,
enableArithAbort: true,
},
pool: {
max: 70,
min: 0,
idTimeoutMillis: 30000,
log: true,
},
};
我一直在测试和测试,但找不到错误所在。希望您能帮助我,我会很感激<3:(