使用 sequelize 连接到 SQL Server 数据库时出错 [英] Error connecting to SQL Server database with sequelize
问题描述
我正在尝试使用 sequelize 连接到 SQL Server 数据库.这是我的连接代码.
I am trying to connect to a SQL Server database using sequelize. Here is my connection code.
var connection = new Sequelize(config.database,config.user,config.password, {
host: config.server,
port: 1433,
dialect: 'mssql'
});
我知道我的配置文件正确地传递了数据.我已经能够连接到 mysql 数据库,但是当我切换到使用 SQL Server 尝试相同时,我没有运气.
I know that my config file is passing in the data correctly. I have been able to connect to a mysql DB, but when I switched to try the same with SQL Server I had no luck.
我在这里缺少某些连接选项吗?我在文档中没有看到有关域的任何信息,所以没有遗漏,这是我对原因的最佳猜测.
Am I missing some connection option here? I didn't see anything about the domain in the documentation, so right no that is missing and it's my best guess at the cause.
这是我得到的错误
message: '无法连接到 HOSTNAME:1433 - 连接 ECONNREFUSED ip.of.ho.st:1433',
message: 'Failed to connect to HOSTNAME:1433 - connect ECONNREFUSED ip.of.ho.st:1433',
这是我的 package.json 文件
Here is my package.json file
{
"name": "sequelizeTest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"sequelize": "^3.19.3",
"tedious": "^1.13.2"
}
}
推荐答案
答案是一个未公开的选项,称为方言选项.对于我的设置,为了连接到我们的 mssql 实例,这是必须的.
The answer was an undocumented option called dialect options. For my setup this was a MUST in order to connect to our mssql instance.
dialectOptions: {
instanceName: INSTANCE_NAME_HERE,
domain: DOMAIN_HERE
}
所以你的整个 Sequelize 实例/连接看起来像这样:
So your whole Sequelize instance/connection looks something like this:
var connection = new Sequelize(config.database,config.user,config.password, {
host: config.smallserver,
dialect: 'mssql',
pool: {
max: 5,
min: 0,
idle: 10000
},
dialectOptions: {
instanceName: config.instancename,
domain: config.domain
}
});
删除死链接
这篇关于使用 sequelize 连接到 SQL Server 数据库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!