添加依赖包```mssql``,ORM的框架sequelize prisma也支持
const sql = require('mssql')
const sqlConfig = {
user: 'user',
password: 'passwor',
database: 'database',
server: '远程主机',
pool: {
max: 10,
min: 0,
idleTimeoutMillis: 30000
},
options: {
encrypt:false, // 重点,不能开启为true
trustServerCertificate: false
}
}
try {
await sql.connect(sqlConfig)
const result = await sql.query(`查询语句`)
console.log(result)
} catch (err) {
console.log(err)
}
}
注意坑: encrypt:false, 必须是false ,必须是false,必须是false