gpt4 book ai didi

mysql - DB 切换到 Idle 状态后出现错误 PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR

转载 作者:太空宇宙 更新时间:2023-11-03 22:26:03 28 4
gpt4 key购买 nike

在非工作时间,数据库进入空闲状态。因此,我使用以下代码片段重新连接数据,

var mysql = require('mysql');
var settings = require('./config.js');

var connection;

function handleDisconnect() {

connection = mysql.createConnection({
host: settings.dbhost,
user: settings.user,
password: settings.password,
database: settings.database
});

connection.connect(function (err) {
if (err) {
console.log('Error when connecting to db:', err, settings.database);
setTimeout(handleDisconnect, 2000);
}
else {
console.log("Database is connected ...", settings.database);
}
});

connection.on('error', function (err) {
console.log('db error', err, settings.database);
if (err.code === 'PROTOCOL_CONNECTION_LOST') {

connection
handleDisconnect();
} else {
throw err;
}
});
}

handleDisconnect();

module.exports = connection;

执行数据库查询时,出现以下错误:

{
"status": 500,
"Error": {
"code": "PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR",
"fatal": false
}
}

关于如何解决这个问题有什么想法吗?

最佳答案

一种可能但不完美的解决方案是使用sql.ConnectionPool()

关于mysql - DB 切换到 Idle 状态后出现错误 PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46109556/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com