2

I am using the following code to connect to 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);
});

I get the error

Invalid object name "undefined.dbo.Person."

Select  * FROM undefined.dbo.Person WHERE FirstName = 'Mathias'

It looks like the servername is not picked up. How can I fix this to connect to the Sql-Server?

Mathias F
  • 15,906
  • 22
  • 89
  • 159

1 Answers1

0

Looks like you just typed an incorrect parameter name (database instead of 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'
});
Viktor
  • 3,436
  • 1
  • 33
  • 42
Raul
  • 1