1 const { Sequelize } = require('sequelize') 2 const qt = require('sequelize').QueryTypes 3 4 const dbCon = new Sequelize("BackupDB", "sa", "Sa12345", { 5 host: "192.168.1.50", 6 port: 1433, 7 dialect: "mssql", 8 dialectOptions: { 9 options: { 10 instanceName: "BENET", 11 encrypt: false, 12 }, 13 }, 14 define: { 15 charset: 'utf8', 16 freezeTableName: true 17 }, 18 pool: { 19 max: 5, 20 min: 2, 21 acquire: 10000, 22 idle: 600000 23 } 24 }); 25 26 const connectDB = async () => { 27 try { 28 await dbCon.authenticate(); 29 console.log("数据库连接测试成功."); 30 } catch (error) { 31 console.log(error); 32 } 33 34 const a = await dbCon.query('select top 2 * from prison where id=$1', { 35 bind: [1], 36 type: qt.SELECT 37 }) 38 console.log(a); 39 } 40 41 connectDB()
主要是记录 instanceName: "BENET" 参数