#[BUGFIX] mssql-node UnhandledPromiseRejectionWarning: ConnectionError: Failed to connect to ip:1433 #sql serverl + express 报错UnhandledPromiseRejectionWarning: ConnectionError: Failed to connect解决

报错

关键报错 “UnhandledPromiseRejectionWarning: ConnectionError: Failed to connect to ip:1433

(node:25104) UnhandledPromiseRejectionWarning: ConnectionError: Failed to connect to 192.168.2.16:1433 - 18588:error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol:c:\ws\deps\openssl\openssl\ssl\statem\statem_lib.c:1958:

    at Connection.<anonymous> (F:\Desktop\gps-monitor-platform\localServer\node_modules\_mssql@6.3.1@mssql\lib\tedious\connection-pool.js:68:17)
    at Object.onceWrapper (events.js:422:26)
    at Connection.emit (events.js:315:20)
    at Connection.socketError (F:\Desktop\gps-monitor-platform\localServer\node_modules\_tedious@6.7.0@tedious\lib\connection.js:1290:12)
    at Socket.<anonymous> (F:\Desktop\gps-monitor-platform\localServer\node_modules\_tedious@6.7.0@tedious\lib\connection.js:1125:14)
    at Socket.emit (events.js:327:22)   
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
#相关代码
exports.basecjh = (callback) => {
    const config = {
        user: "sa",
        password: "cjh13396943871.",
        server: "192.168.2.16", // You can use ‘localhost\\instance‘ to connect to named instance
        database: "Erp_Proj_DataBase",
        options: {
            enableArithAbort: false,
        },
    };
    (async function() {
        try {
            let pool = await sqlserver.connect(config);
            console.log("trigger");
            let result1 = await pool
                .request()
                // .input("input_parameter", sqlserver.Int, value)
                .query("select * from t_apply");
            // console.dir(result1)
......            

解决

增加一行: config.options.encrypt: false, 即可解决。

exports.basecjh = (callback) => {
    const config = {
        user: "sa",
        password: "cjh13396943871.",
        server: "192.168.2.16", // You can use ‘localhost\\instance‘ to connect to named instance
        database: "Erp_Proj_DataBase",
        options: {
            enableArithAbort: false,
            encrypt: false,#增加该行
        },
......        

说明:

相关的说明在文档里只找到了简单的一段描述:

https://github.com/tediousjs/node-mssql#configuration

  • Parts of the connection URI should be correctly URL encoded so that the URI can be parsed correctly.
  • options.encrypt - A boolean determining whether or not the connection will be encrypted (default: true).

#[BUGFIX] mssql-node UnhandledPromiseRejectionWarning: ConnectionError: Failed to connect to ip:1433 #sql serverl + express 报错UnhandledPromiseRejectionWarning: ConnectionError: Failed to connect解决

但是没有找到更加深层次的说明,文档上只是说用以给“connection” 进行编码。 应该不是通信协议层面上的编码,因为设定为false后反而连接成功。 这里编码后反而无法连接,不知道具体原因。可能是远端需要对应的解码? 有可能是处于安全上的考虑? 这个问题以后可以在留意以下。

#[BUGFIX] mssql-node UnhandledPromiseRejectionWarning: ConnectionError: Failed to connect to ip:1433 #sql serverl + express 报错UnhandledPromiseRejectionWarning: ConnectionError: Failed to connect解决

上一篇:mysql面试题总结


下一篇:mysql中字符查询与替换