Home:ALL Converter>Certificate error when connecting to SQL Server

Certificate error when connecting to SQL Server

Ask Time:2020-02-14T20:27:08         Author:Gustavo Henrique

Json Formatter

When trying to connect to SQL Server, I get the following error:

(node:9364) UnhandledPromiseRejectionWarning: ConnectionError: Failed to connect to 10.120.6.11:1433 - self signed certificate

When I use SQL Server 2014, it works normally.

Note: You need a vpn to connect.

Code:

const config = {
  port: parseInt(process.env.DB_PORT, 10),
  server: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASS,
  database: process.env.DB_Database,
  stream: false,
  options: {
    trustedConnection: true,
    encrypt: true,
    enableArithAbort: true,
    trustServerCertificate: false,

  },
}

sql.connect(config).then(pool => {
  if (pool.connecting) {
    console.log('Connecting to the database...')
  }
  if (pool.connected) {
    console.log('Connected to SQL Server')
  }
})

Author:Gustavo Henrique,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60226370/certificate-error-when-connecting-to-sql-server
bbien :

I had the same error message (Failed to connect to xxx:1433 - self signed certificate). Then I used trustServerCertificate: true. This fixed the error for me.",
2020-07-09T13:19:30
yy