sql server - Is there a way to specify the database when defining Tedious configuration (Node.js)? -
according tedious getting started guide, connecting database done this:
var connection = require('tedious').connection; var config = { username: 'test', password: 'test', server: '192.168.1.210', // if you're on windows azure, need this: options: {encrypt: true} }; var connection = new connection(config); connection.on('connect', function(err) { // if no error, go... executestatement(); } );
once connection has been established, query can performed this:
var request = require('tedious').request; function executestatement() { request = new request("select 42, 'hello world'", function(err, rowcount) { if (err) { console.log(err); } else { console.log(rowcount + ' rows'); } }); request.on('row', function(columns) { columns.foreach(function(column) { console.log(column.value); }); }); connection.execsql(request); }
this works charm however, want change request following:
request = new request("select * table", function(err, rowcount) {
obviously, not work because there no database defined in config object therefore, sql not recognise table.
i have tried adding following config object:
database: 'mydb'
i still getting following error:
invalid object name 'table'.
what correct way define database in config object?
the config object needs this:
var config = { username: 'username', password: 'password', server: 'server', options: { database: "databasename", } };
Comments
Post a Comment