Node.js 节点出现错误时SQL Server重新连接
我有以下代码:Node.js 节点出现错误时SQL Server重新连接,node.js,tedious,Node.js,Tedious,我有以下代码: var connection = new Connection(config); connection.on('connect', function (err) { if (err) { console.log("Error connecting to the db", err); connection.close(); } else { console.log('Connected to: ',
var connection = new Connection(config);
connection.on('connect', function (err) {
if (err) {
console.log("Error connecting to the db", err);
connection.close();
} else {
console.log('Connected to: ', config.options.database);
}
});
connection.on('end', function(err) {
console.log("On close called");
if(err) {
console.log("error closing connection", err);
connection.close();
} else {
try {
connection.connect();
} catch(err) {
console.log("erorr on connect", err);
connection.close();
}
}
});
connection.connect();
module.exports = connection;
我希望代码在出现错误时重新连接,但我得到了以下异常:
连接连接出错错误:。无法在处于最终
状态的连接上调用connect
我尝试了连接重置和取消,但它似乎仍然处于最终状态