简体   繁体   中英

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

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:

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

encrypt: true更改为encrypt: false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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