Home > Back-end >  Node error connecting to SQL Server 2019 won't go away
Node error connecting to SQL Server 2019 won't go away

Time:05-20

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

CodePudding user response:

change encrypt: true to encrypt: false

  • Related