node Sequelize使用
module.exports.cityOneSequelize = new Sequelize("db_name", "user", "pass", { host: "127.0.0.1", port: 1433 dialect: "mssql", dialectOptions: { requestTimeout: 3600000 }, options: { encrypt: false }, // logging: false, pool: { max: 5 } });
默认查询15s超时,如果有慢查询的话,需要按上面所示设置requestTimeout。
数据库是sql server时,要用到tedious组件,否则会报错,如下
所以,需要我们在package.json中引入mssql驱动的同时引入tedious组件。
实践表明,当sql server服务端版本比较低时(生产中是sql server 2005和sql server 2008),mssql的版本高点无所谓,但是tedious的版本不能太高,5.0.0及以下都是可以的,6.0.0版本就会报SequelizeConnectionError: Failed to connect to xxx - Cannot call write after a stream was destroyed。