2

我正在使用以下代码连接到 Ms SQL-Server

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?

4

1 回答 1

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'
});
于 2016-06-22T22:50:31.303 回答