You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用NodeJS+mssql包连接SQL Server 2012遇SSL协议不支持错误

问题描述

在MacOS Monterey系统中使用Node.js的mssql包开发,连接SQL Server数据库时无法建立连接,相关代码、错误信息及依赖配置如下:

连接代码

import mssql from "mssql"

connect = async () => {
    try {
      var cfg = {
        server: "10.0.0.180",
        authentication: {
          type: "default",
          options: {
            userName: "username",
            password: "password",
          },
        },
        options: {
          encrypt: true,
          enableArithAbort: true,
          integratedSecurity: true,
          trustServerCertificate: true,
          rowCollectionOnDone: true,
          database: "db",
          cryptoCredentialsDetails: {
            // Required for SQL Server 2012 connection,
            // as node 18 uses a newer TLS protocol
            minVersion: "TLSv1",
          },
        },
      };

      let conn = await mssql.connect(cfg);

      return conn;
    } catch (error) {
      return null;
    }

    return false;
  };

错误信息

ConnectionError: Failed to connect to 10.0.0.180:1433 - 0036761901000000:error:0A000102:SSL routines:ssl_choose_client_version:unsupported protocol:../deps/openssl/openssl/ssl/statem/statem_lib.c:1986:

项目依赖配置

"dependencies": {
    "mssql": "^9.0.1",
    "nconf": "^0.12.0",
    "qs": "^6.11.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.2",
    "@babel/node": "^7.20.2",
    "@babel/preset-env": "^7.20.2",
    "babel-loader": "^9.1.0",
    "webpack": "^5.75.0",
    "webpack-cli": "^4.10.0"
  }

问题原因

  1. TLS协议版本不兼容:Node.js 18默认采用OpenSSL 3.0,该版本已移除对TLSv1.0的支持;而你连接的SQL Server 2012默认仅支持TLSv1.0,代码中指定的minVersion: "TLSv1"(对应TLSv1.0)无法被Node.js 18的SSL库识别,导致握手失败。
  2. 认证配置冲突:代码中同时启用了authentication.type: "default"(账号密码认证)和integratedSecurity: true(Windows集成认证),两个配置互斥,会干扰正常的认证流程。

内容的提问来源于stack exchange,提问作者Mendes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 21:50:33