• #[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:wsdepsopensslopensslsslstatemstatem_lib.c:1958:
    
        at Connection.<anonymous> (F:Desktopgps-monitor-platformlocalServer
    ode_modules\_mssql@6.3.1@mssqllib	ediousconnection-pool.js:68:17)
        at Object.onceWrapper (events.js:422:26)
        at Connection.emit (events.js:315:20)
        at Connection.socketError (F:Desktopgps-monitor-platformlocalServer
    ode_modules\_tedious@6.7.0@tediouslibconnection.js:1290:12)
        at Socket.<anonymous> (F:Desktopgps-monitor-platformlocalServer
    ode_modules\_tedious@6.7.0@tediouslibconnection.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: "cxxxxxxxx.",
            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).

    image-20210505133833309

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

  • 相关阅读:
    hdoj 1305字典树水题之二
    nyoj 547 水池加水 priority_queue优先级队列初体验
    nyoj167 找奶牛病毒 “按位或”运算 递归
    HDOJ4525 吃鸡腿 腾讯马拉松(五)
    hdoj 4523 切蛋糕 腾讯马拉松 大数加法比较
    如何学好3D游戏引擎编程《转自3D游戏引擎网》
    priority_queue 优先级队列的基本应用和重载问题
    poj1611 传染病 并查集
    srand((unsigned)time(NULL))和rand()
    最近被一个windows mobile照相的问题给难住了
  • 原文地址:https://www.cnblogs.com/jaycethanks/p/14731593.html
Copyright © 2020-2023  润新知