0

I followed this question here using mssql 5.0.4

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

and I always get the

pool.request() is not a function

exception. What did I do wrong.

Exactly same '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
}

and the call at:

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)
    }
  })
}
TX T
  • 817
  • 2
  • 16
  • 25
  • You never declared the pool.request function. On the link you just posted, check `routes/set1.js` file. – Nicolas Hevia Mar 28 '19 at 02:55
  • @Rasnick, what do you mean I did not declare the pool.request. It is under the comment // RUNTIME ... – TX T Mar 28 '19 at 03:13

0 Answers0