首页 > 解决方案 > 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状态的连接上调用

我尝试了连接重置和取消,但它似乎仍处于最终状态。

标签: node.jstedious

解决方案


推荐阅读