I'm getting a connection error when trying to automatically create the db table models using sequelize-automate.
However, the connection I'm using for sequelize is working but it's in a different format and I'm not sure if sequelize-automate allows me to use the same format.
const Sequelize = require('sequelize');
const util = require('util');
const dbSequelize = require('../public/dbconfigSequelize.json');
let databaseUrl = util.format(
dbSequelize.server,
dbSequelize.username,
dbSequelize.password,
dbSequelize.host,
dbSequelize.database
)
function getConnection() {
console.log('creating a new connection');
return new Sequelize(databaseUrl, {
pool: {
max: 1
},
logging: console.log
});
}
function checkAuthenticate() {
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});
}
const sequelize = getConnection();
checkAuthenticate();
module.exports = sequelize;
package.json
"scripts": {
"generate-sequelize-models": "sequelize-automate -c sequelize-automate.config.json"
}
sequelize-automate.config.json
{
"dbOptions": {
"database": "mydbname",
"username": "myusername",
"password": "mypassword",
"dialect": "mssql",
"host": "localhost",
"logging": false
},
"options": {
"type": "js",
"dir": "./server/models"
}
}
The error:
PS C:\Users\username\Documents\myelectronapp> npm run generate-sequelize-models
> myelectronapp@0.1.0 generate-sequelize-models C:\Users\username\Documents\myelectronapp
> sequelize-automate -c sequelize-automate.config.json
Database options: {"database":"mydbname","username":"myusername","password":"****","dialect":"mssql","host":"localhost","port":3306,"logging":false}
Automate options: {"type":"js","camelCase":false,"dir":"./server/models","emptyDir":false}
ConnectionError [SequelizeConnectionError]: Failed to connect to localhost:3306 - Could not connect (sequence)
at C:\Users\username\Documents\myelectronapp\node_modules\sequelize\lib\dialects\mssql\connection-manager.js:134:17
at tryCatcher (C:\Users\username\Documents\myelectronapp\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\username\Documents\myelectronapp\node_modules\bluebird\js\release\promise.js:547:31)
at Promise._settlePromise (C:\Users\username\Documents\myelectronapp\node_modules\bluebird\js\release\promise.js:604:18)
at Promise._settlePromise0 (C:\Users\username\Documents\myelectronapp\node_modules\bluebird\js\release\promise.js:649:10)
at Promise._settlePromises (C:\Users\username\Documents\myelectronapp\node_modules\bluebird\js\release\promise.js:725:18)
at _drainQueueStep (C:\Users\username\Documents\myelectronapp\node_modules\bluebird\js\release\async.js:93:12)
at _drainQueue (C:\Users\username\Documents\myelectronapp\node_modules\bluebird\js\release\async.js:86:9)
at Async._drainQueues (C:\Users\username\Documents\myelectronapp\node_modules\bluebird\js\release\async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\username\Documents\myelectronapp\node_modules\bluebird\js\release\async.js:15:14)
at processImmediate (internal/timers.js:456:21) {
name: 'SequelizeConnectionError',
parent: ConnectionError: Failed to connect to localhost:3306 - Could not connect (sequence)
at ConnectionError (C:\Users\username\Documents\myelectronapp\node_modules\tedious\lib\errors.js:13:12)
at Connection.socketError (C:\Users\username\Documents\myelectronapp\node_modules\tedious\lib\connection.js:1288:56)
at C:\Users\username\Documents\myelectronapp\node_modules\tedious\lib\connection.js:1114:21
at SequentialConnectionStrategy.connect (C:\Users\username\Documents\myelectronapp\node_modules\tedious\lib\connector.js:87:14)
at Socket.onError (C:\Users\username\Documents\myelectronapp\node_modules\tedious\lib\connector.js:100:12)
at Socket.emit (events.js:311:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
message: 'Failed to connect to localhost:3306 - Could not connect (sequence)',
code: 'ESOCKET'
},
original: ConnectionError: Failed to connect to localhost:3306 - Could not connect (sequence)
at ConnectionError (C:\Users\username\Documents\myelectronapp\node_modules\tedious\lib\errors.js:13:12)
at Connection.socketError (C:\Users\username\Documents\myelectronapp\node_modules\tedious\lib\connection.js:1288:56)
at C:\Users\username\Documents\myelectronapp\node_modules\tedious\lib\connection.js:1114:21
at SequentialConnectionStrategy.connect (C:\Users\username\Documents\myelectronapp\node_modules\tedious\lib\connector.js:87:14)
at Socket.onError (C:\Users\username\Documents\myelectronapp\node_modules\tedious\lib\connector.js:100:12)
at Socket.emit (events.js:311:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
message: 'Failed to connect to localhost:3306 - Could not connect (sequence)',
code: 'ESOCKET'
}
}
Check this out, this is not from sequelize-automate but quite likely your issue is not particular to that anyway, otherwise it would be well documented by others
https://github.com/typeorm/typeorm/issues/2133
can't help but notice the error in the title is not the same as the error in your trace above either... why is it using default port for mySQL instead of mssql