[英]SQL Server is not connecting with node app
我正在尝试使用 Sequelize ORM 将我的 nodejs/express 应用程序连接到 SQL Server 2017。 这是我第一次使用 SQL Server。 我不确定问题出在哪里。
情况:-
我使用 SQL Server Management Studio 创建了一个数据库
我在安全 > 登录下创建了另一个用户(例如:-用户名、密码)
并使该用户成为该数据库的所有者
问题:
当我尝试使用 Management Studio(使用 SQL Server 身份验证)连接到 SQL Server 时,每次都会建立连接。
但是当我尝试将同一个数据库与我的 nodejs 应用程序连接时,出现错误:
错误:- [SequelizeAccessDeniedError:用户''的登录失败]##
注意:我已经尝试过mssql
npm 包,但无法从 nodejs 连接到 SQL Server
这是我使用 sequelize 编写 index.js 文件的代码
const express = require('express');
const app = express();
const Sequelize = require('sequelize');
const sequelize = new Sequelize("demo", "demoUser", "dPass", {
host: "localhost",
dialect: "mssql",
pool: {
max: 1,
min: 0,
idle: 5000,
acquire: 5000
},
dialectOptions: {
encrypt: true
}
});
sequelize
.authenticate()
.then(() => {
console.log("connection established");
})
.catch(err => {
if (err) {
console.log(`unable to connect database Error ${err}`);
}
});
app.listen(3000, (err) => {
if (err) throw err;
console.log("Server connect to port 3000");
})
你必须添加 npm 包sequelize-msnodesqlv8
const Sequelize = require('sequelize'); let connectionString = { dialect: 'mssql', dialectModulePath: 'msnodesqlv8/lib/sequelize', dialectOptions: { driver: "SQL Server Native Client 11.0", instanceName: 'MSSQLSERVER',//in my condition //check it in server configuration manager which instance is running trustedConnection: true }, host: 'localhost', database: 'dbname' } const sequelize = new Sequelize(connectionString);
驱动程序-转到 odbc 驱动程序
然后在“系统 dns”选项卡中
添加
选择 SQL Server Native Client 11.0 然后按完成
将名称设为 SQL Server Native Client 11.0 然后从下拉列表中选择服务器然后下一步
下一个
下一个
下一个
结束
测试数据源
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.