I want to connect and Request from MSSQL using nodejs to link it with magento.
I Am trying to fix it for days now but it ends on the same way…
This is my Error Code:
Connected
{ RequestError: Requests can only be made in the LoggedIn state, not the Connecting state
at RequestError (C:WorkspaceVisual-CodenodeApinode_modulestediousliberrors.js:34:12)
at Connection.makeRequest (C:WorkspaceVisual-CodenodeApinode_modulestediouslibconnection.js:1423:33)
at Connection.execSql (C:WorkspaceVisual-CodenodeApinode_modulestediouslibconnection.js:1194:19)
at executeStatement (C:WorkspaceVisual-CodenodeApinodeapi.js:41:20)
at Connection.<anonymous> (C:WorkspaceVisual-CodenodeApinodeapi.js:14:9)
at emitOne (events.js:116:13)
at Connection.emit (events.js:211:7)
at Connection.socketError (C:WorkspaceVisual-CodenodeApinode_modulestediouslibconnection.js:869:14)
at C:WorkspaceVisual-CodenodeApinode_modulestediouslibconnection.js:739:25
at GetAddrInfoReqWrap.callback (C:WorkspaceVisual-CodenodeApinode_modulestediouslibconnector.js:68:18)
message: 'Requests can only be made in the LoggedIn state, not the
Connecting state',
code: 'EINVALIDSTATE' }
I searched a lot and found similar problems but nothing solved it…
This is my Code maybe you can help me Spot the mistake.
var Connection = require('tedious').Connection;
var config = {
userName: 'Cool userName',
password: 'awesome password',
server: 'amazing server',
options: {
database: 'database',
}
};
var connection = new Connection(config);
connection.on('connect', function(err) {
// If no error, then good to proceed.
console.log("Connected");
executeStatement();
});
var Request = require('tedious').Request;
var TYPES = require('tedious').TYPES;
function executeStatement() {
request = new Request("select * from Artikelstamm;", function(err) {
if (err) {
console.log(err);}
});
var result = "";
request.on('row', function(columns) {
columns.forEach(function(column) {
if (column.value === null) {
console.log('NULL');
} else {
result+= column.value + " ";
}
});
console.log(result);
result ="";
});
request.on('done', function(rowCount, more) {
console.log(rowCount + ' rows returned');
});
connection.execSql(request);
}
2
Answers
Set Firewall rule to your DB by adding CleintIP. In Azure SQLDB, there is SET FIREWALL RULE button. You can use it to add IP.
Add this event to your request