Ошибка «ConnectionError [SequelizeConnectionError]: не удалось подключиться к локальному узлу: 1443 - Не удалось подключиться (последовательность)» с помощью sequelize-automate - PullRequest
0 голосов
/ 02 марта 2020

Я получаю сообщение об ошибке подключения при попытке автоматического создания моделей таблиц БД с помощью sequelize-automate.

Однако подключение, которое я использую для sequelize, работает, но оно в другом формате, и я Я не уверен, позволяет ли sequelize-automate использовать тот же формат.

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;

пакет. 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"
  }
}

Ошибка:

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'
  }
}

1 Ответ

1 голос
/ 02 марта 2020

Проверьте это, это не от sequelize-автоматизировать, но вполне вероятно, что ваша проблема не относится к этому в любом случае, в противном случае это было бы хорошо задокументировано другими

https://github.com/typeorm/typeorm/issues/2133

не могу не заметить, что ошибка в названии не совпадает с ошибкой в ​​приведенной выше трассировке ... почему он использует порт по умолчанию для mySQL вместо ms sql

...