使用以下繁琐的代码,我可以成功连接到Azure SQL Server。
const Connection = require('tedious').Connection; const connection = new Connection({ userName: '[USER]', password: '[PASSWORD]', server: '[HOSTNAME]', options: {encrypt: true} }); connection.on('connect', (err) => { if (err) { console.log('error connecting', err); } else { console.log('connection successful'); } });
但是,使用等效的Sequelize代码,我会收到连接超时错误。
const Sequelize = require('sequelize'); const sequelize = new Sequelize('[DBNAME]', '[USER]', '[PASSWORD]', { dialect: 'mssql', host: '[HOSTNAME]', dialectOptions: { encrypt: true } }); sequelize.authenticate().then((err) => { console.log('Connection successful', err); }) .catch((err) => { console.log('Unable to connect to database', err); });
有什么想法吗?
使用:sequelize 3.29.0,乏味的1.14.0,SQL Server v12
我遇到错误了
SequelizeConnectionError: Server requires encryption, set 'encrypt' config option to true.
我使用Azure SQL数据库进行了尝试,以下方法对我有效。
const sequelize = new Sequelize('DB Name', 'Username', 'Password', { host: 'Host', dialect: 'mssql', dialectOptions: { options: { encrypt: true, } } });