gpt4 book ai didi

node.js - 使用 sequelize-automate 时出错 "ConnectionError [SequelizeConnectionError]: Failed to connect to localhost:1443 - Could not connect (sequence)"

转载 作者:行者123 更新时间:2023-12-03 22:23:19 29 4
gpt4 key购买 nike

尝试使用 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'
}
}

最佳答案

看看这个,这不是来自 sequelize-automate 但很可能你的问题无论如何都不是特别的,否则其他人会很好地记录下来

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

不禁注意到标题中的错误与上面跟踪中的错误不同......为什么它使用 mySQL 的默认端口而不是 mssql

关于node.js - 使用 sequelize-automate 时出错 "ConnectionError [SequelizeConnectionError]: Failed to connect to localhost:1443 - Could not connect (sequence)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60483390/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com