I have a virtual box running Ubuntu on my local machine. I have installed nodejs as well as tedious the mssql driver. I'm attempting to pull data from a remote mssql server from a query and return json.
I've read through quite a bit of documentation the first question I would just like answered is do you have to run Nodejs on a windows box to connect to mssql server?
(I am under the impression this is the case when using the standards nodejs windows driver.)
The second question I have stepped through all of my process and the node server is functioning fine but when I get to the mssql call I'm getting the following error:
Invalid state; requests can only be made in the LoggedIn state, not the SentLogin7WithStandardLogin state
I have not found anyone else that has run into this error with the same situation as myself. I have tried sending the request with the object formation as suggested in this fix.
How do I connect to SQL Azure from NodeJS/Tedious?
I'm still getting the same error as mentioned before. So here is the code. I'm using restify was hoping just to make a restful api our of my nodejs server and spit back json from my mssql calls.
var restify = require('restify');
var Connection = require('tedious').Connection;
var server = restify.createServer();
server.listen(8080,function(){
console.log('%s listening at %s',server.name,server.url);
server.get('/GetInfo',GetInfo);
});
function GetInfo(req, res, next){
console.log('Starting GetInfo function ...');
res.header('Content-Type:application/json');
var config = {
user:'awesomeusername',
password:'awesomepassword',
server:'coolservername',
options:{
encrypt:true,
database:'TableName'
}
};
var connection = new Connection(config);
var Request = require('tedious').Request;
var sql = "SELECT ColumnName FROM Database.dbo.TableName";
connection.on('connect',function(err){
request = new Request(sql,function(err,rowCount){
if(err){
res.write(err);
console.log('got an error %s',err)
}else{
res.write(rowCount+'rows');
}
});
request.on('row',function(columns){
columns.forEach(function(column){
res.write(column.value);
});
});
connection.execSql(request);
});
}
So there you have I'm a complete novice with nodejs I thought I would give it a try. Any tips or information is appreciated. Thanks in advance.