gpt4 book ai didi

sql-server - 如何使用 mssql 配置 sequelize?

转载 作者:行者123 更新时间:2023-12-03 22:17:32 25 4
gpt4 key购买 nike

我想使用 sequelize 连接 Microsoft Sql。我找到了这个链接 http://docs.sequelizejs.com/manual/installation/getting-started.html

我用nodejs编写了下面的代码:

require('dotenv').config();
var express = require('express');
var app = express();
const Sequelize = require('sequelize');

const sequelize = new Sequelize(process.env.DB_NAME,null,null, {
dialect: 'mssql',
host: process.env.DB_HOST + "\\" + process.env.DB_SERVER,
operatorsAliases: false,

pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}

});

sequelize.authenticate().then((err) => {
console.log('Connection successful', err);
})
.catch((err) => {
console.log('Unable to connect to database', err);
});

app.listen(process.env.PORT);
console.log('Starting Server on Port ', process.env.PORT);

但是当我运行代码时出现错误:
sequelize deprecated String based operators are now deprecated. Please use 
Symbol based operators for better security, read more at
http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
node_modules\sequelize\lib\sequelize.js:242:13
Unable to connect to database { SequelizeHostNotFoundError: Failed to
connect to USER-PC\SQLEXPRESS:1433-getaddrinfo ENOTFOUND USER-PC\SQLEXPRESS
at Connection.connection.on.err (C:\Users\User\Desktop\loginApp\node_modules
\sequelize\lib\dialects\mssql\connection-manager.js:98:22)

我做错了什么,无法连接到数据库?

最佳答案

您需要为数据库提供mysql数据库名称、用户名和密码

var sequelize= new Sequelize('your Database name', 'username', 'password', {
host: 'localhost',
dialect: 'mssql', //postgres'|'sqlite'|''|'mysql',

pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},

// SQLite only
//storage: 'path/to/database.sqlite'
});

关于sql-server - 如何使用 mssql 配置 sequelize?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49775451/

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