简体   繁体   中英

TypeError: Cannot read property '_pool' of undefined

I'm trying to release the query after executing it successfully to prevent the query to stay in the pool but faced an error of

TypeError: Cannot read property '_pool' of undefined.

router.get('/articles', (req, res) => {
  let sql = "SELECT * FROM ARTICLES";
  myDB.query(sql, (error, results) => {
    myDB.releaseConnection();
    if (error) {
      console.log(error);
    } else {
      res.send(results)
    }
  })
});

and this is my connection

const mysql = require('mysql');
const myDB = mysql.createPool({
    connectionLimit: 10,
    host: 'server.address.here',
    user: 'hmidev',
    password: 'hmidev',
    database: 'VD_NEW_WEBSITE'
});

myDB.getConnection((error) => {
    if (error) {
        console.log(error);
    } else {
        console.log(`Successfully connected at VD_NEW_WEBSITE`);
    }
});

module.exports = myDB;

This is what my database looks like:

数据库映像

EDIT: Added image

Are you working on the localhost? If you are Working on the localhost, you need to change your host to localhost

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM