我使用以下代码连接到Ms-SQL
var node_mssql = require('node-mssql');
/* add configuration to query object */
var queryObj = new node_mssql.Query({
host: '127.0.0.1', // You can use 'x.x.x.x\\instance' to connect to named instance
port: 1433,
username: 'myuser',
password: 'mypwd',
database: 'persondb'
});
/* set table name to operate */
queryObj.table('dbo.Person');
/* set update query condition */
queryObj.where({
'FirstName': 'Mathias',
})
/* run update query and fetch response */
queryObj.select(function(results) {
// success callback
console.log(results);
}, function(err, sql) {
// failed callback
if(err)
console.log(err);
console.log(sql);
});
我收到错误
Invalid object name "undefined.dbo.Person."
Select * FROM undefined.dbo.Person WHERE FirstName = 'Mathias'
看起来服务器名称未被提取。如何解决此问题以连接到Sql-Server?
答案 0 :(得分:0)
您似乎只输入了错误的参数名称(database
而不是db
):
var queryObj = new node_mssql.Query({
host: '127.0.0.1', // You can use 'x.x.x.x\\instance' to connect to named instance
port: 1433,
username: 'myuser',
password: 'mypwd',
db: 'persondb'
});