mssql ConnectionPool request()异常不是功能

时间:2019-03-28 01:45:41

标签: node.js sql-server

我在这里使用mssql 5.0.4跟踪了这个问题

How can I use a single mssql connection pool across several routes in an Express 4 web application?

我总是得到

pool.request() is not a function

例外。我做错了什么。

完全相同的“ db.js”

const sql = require('mssql')
const config = {/*...*/}

const poolPromise = new sql.ConnectionPool(config)
  .connect()
  .then(pool => {
    console.log('Connected to MSSQL')
    return pool
  })
  .catch(err => console.log('Database Connection Failed! Bad Config: ', err))

module.exports = {
  sql, poolPromise
}

和以下电话:

const { poolPromise } = require('./db')

module.exports = {
  get: async (req, res) => {
    try {
      const pool = await poolPromise
      // RUNTIME ERROR EXCEPTION at the following line
      const result = await pool.request()
          .query('select * from cars')      

      res.json(result.recordset)
    } catch (err) {
      res.status(500)
      res.send(err.message)
    }
  })
}

0 个答案:

没有答案