node.js - SQL Server 重新连接来自 nodejs 的错误
问题描述
我有以下代码:
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;
我期待代码在出现错误时重新连接,但我得到了这个异常:
连接时出错 ConnectionError:
.connect
无法在处于Final
状态的连接上调用
我尝试了连接重置和取消,但它似乎仍处于最终状态。
解决方案
推荐阅读
- c# - 如何在 ListView Tableheader Link 上保持样式(以编程方式设置值后)
- ocaml - 为什么不能将带有可选参数的函数强制转换为没有它们的函数?
- python-3.x - 如果正在使用 unitest,则自动脚本不会运行
- python - 如何将 json 传递给 render_to_response
- python - 如何解决 Python OSError:[Errno 22] Linux 上的无效参数
- android - 广告:广告加载失败:3
- javascript - 如何使范围滑块的左侧与滑块右侧的颜色不同?
- dart - 错误:参数类型'(文件)→未来
'不能分配给参数类型'(动态)→FutureOr ' - ftp - VScode:如何设置本地编辑和 ftp 部署
- reactjs - htaccess 通过 URL 访问不同的子文件夹