我正在尝试从nodeJS
连接到我本地机器上的Sql Server。当我运行应用程序时,会抛出以下错误:
Login failed for user \'admin\'.', code: 'ELOGIN' },
这是我的连接详细信息:
const sql = require('mssql');
const config = {
host:'localhost',
user:'admin',
password:'password',
database:'database',
server:'localhost\\SQLEXPRESS'
}
const poolPromise = new sql.ConnectionPool(config)
.connect()
.then(pool => {
console.log('Connected to localhost '+ config.database +' database');
return pool;
})
.catch(err => console.log('Database connection failed. Error: ', err));
module.exports = {
sql, poolPromise
}
这个 PoolPromise 被用于某些仓库文件中,以此来管理像这样从数据库获取的数据:
const { poolPromise } = require('./pool');
module.exports = {
create: async function (name) {
const pool = await poolPromise;
return await pool.request()
.input('nameParameter', name)
.query('INSERT INTO dbo.table(nombre) VALUES (@nameParameter)')
.then(result => {
console.log(result);
}).catch(function(err) {
console.log(err.message);
});
},
我尝试安装msnodesqlv8
模块,但它无法工作。我的npm版本是npm: '6.4.1'
。
我正在为解决这个问题苦苦挣扎。有什么想法吗?