简体   繁体   English

连接到 SQL Server 2019 的节点错误不会消失

[英]Node error connecting to SQL Server 2019 won't go away

i'm having some trouble connecting node to the database, it keeps throwing me an error of ssl and i tried a lot of different videos and stuff to see if it works but nothing does, here is what i'm currently doing我在将节点连接到数据库时遇到了一些问题,它不断向我抛出 ssl 错误,我尝试了很多不同的视频和东西来查看它是否有效,但没有任何效果,这就是我目前正在做的

import sql from 'mssql'

const dbSettings = {
    user: 'admin',
    password: 'system',
    server: 'localhost',
    database: 'master',
    options: {
        trustedConnection: true,
        encrypt: true,
        trustServerCertificate: true,
    },
}

async function getConnection() {
const pool =  sql.connect(dbSettings)
const result = await sql.query("SELECT 1")
console.log(result)
}
getConnection()

i also tried this as well but didn't work either我也试过这个,但也没有用

async function getConnection() {
const pool = await sql.connect(dbSettings)
const result = await pool.request().query("SELECT 1")
console.log(result)

i also checked if the SQL Server authentication is enabled with windows and SQL Server and it is, i can log in into SQL Server with that info, but somehow is having trouble creating the connection, by the way, this is the error message it is showing me:我还检查了 Windows 和 SQL Server 是否启用了 SQL Server 身份验证,我可以使用该信息登录到 SQL Server,但不知何故在创建连接时遇到了问题,顺便说一下,这是错误消息向我展示:

node_modules\mssql\lib\tedious\connection-pool.js:70
          err = new ConnectionError(err)
                ^

ConnectionError: Failed to connect to localhost:1433 - 186B0000:error:0A000102:SSL routines:ssl_choose_client_version:unsupported protocol:c:\ws\deps\openssl\openssl\ssl\statem\statem_lib.c:1986

any tips or solution you can give me to solve this problem would be really helpful to me, thank you very much in advance.您可以给我解决此问题的任何提示或解决方案将对我非常有帮助,非常感谢您。

EDIT编辑

I noticed that the connection error only appears when i call the function getConnection if i remove it it doesn't appear, however i need to make sure that the connection was properly established and see the response from the database to move on我注意到连接错误仅在我调用函数 getConnection 时出现

encrypt: true更改为encrypt: false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM