Node.js SQL Server driver issue - How to troubleshoot - node.js

What is the correct way to troubleshoot this error with Node.js on Windows with the SQL Server driver.
events.js:2549: Uncaught Error: 42000: [Microsoft][SQL Server Native Client 11.0
]Syntax error, permission violation, or other nonspecific error
It is not the SQL statement - it works in other tools - like .NET
Doesn't seem to be the SQL connection info - it works in other tools - like .NET
Any thoughts? What is the correct way for completely uninstalling node.js and starting over. I don't think my last install removed all my global modules.
var sql = require('node-sqlserver');
var _ = require('underscore')._;
var connstr = "Driver={SQL Server Native Client 11.0};Server=localhost;" +
"Initial Catalog=CDDB;Trusted_Connection={Yes}";
sql.open(connstr, function (err, conn) {
if (err) {
console.log("Error opening the connection");
return;
} else {
var stmt = "select top 10 * from Client";
conn.query(connstr, stmt, function (err, results) {
if (err) {
console.log("Error running query!");
return;
}
_.each(results, function (row) {
console.log(row[0]);
});
});
}
});

First idea : Are users which runs your node.exe process and the one defined on your application pool - or maybe your current user account if you are using VS.NET to check your code are the same ?
To troubleshoot :
I would use node-inspector - it allows to set up breakpoints onto your node.js code
To install it :
npm install -g node-inspector
To run it :
node --debug your-nodeapp-file.js
Launch another command line and run the following program :
node-inspector
Sorry but i do not have SQL Server to try your code, hope this help anyway.

Related

Module `fs` does not exist in the Haste module map

I'm new to Node.js and react-native. I followed the sample on send_telemetry.js exactly but when I run my react-native app I get an error: "The development server returned response error code 500.
the error message is:
bundling failed: Error: Unable to resolve module fs from ProjectPath\node_modules\azure-iot-device\lib\module_client.js: Module fs does not exist in the Haste module map";
Im running:
Node.js v10.15.3
NPM 6.4.1
react-native#0.59.2
First error was the same with Unable to resolve module events,
I can install events,
but the fs module is: "This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it."
var Protocol = require('azure-iot-device-http').Http;
var DeviceClient = require('azure-iot-device').Client;
var Message = require('azure-iot-device').Message;
var connectionString = 'my connection string';
var client = DeviceClient.fromConnectionString(connectionString, Protocol);
function ConnectionTest(err) {
if (err) {
console.log('Could not connect: ' + err);
} else {
console.log('Client connected');
}
client.close(function () {
process.exit(0);
});
};
export async function Test() {
client.open(ConnectionTest);
};
Basically I need to know how to get the azure IOT hub client working in my react-native app (not using Expo).
Im pretty much stumped so any help would greatly be appreciated.
A dependency module is missing ... which is fs ...
this file-system npm module is incompatible with react-native ... cause it has it own different environment.
I had "import { symlink } from 'fs';" randomly pop up in one of my scripts. Once I deleted this line same issue you had went away. I would search your whole project for that line.

Unspecified System Error using nodejs driver to connect to informix

I have this connection below. Works well in windows server but when in linux it doesnt. It provides this erro msg :an error occured:> Error: [Informix][Informix ODBC Driver][Informix]Unspecified System Error = -23101.
when I check on the error code using finderr it says the locale environment variables DB_LOCALE and CLIENT_LOCALE has problem how do I go about this? How can I set the locales or find the problem and solve it. Note that I have installed the CSDK and set the environment varibales as required my connection is as below code.
var ibmdb = require("ifxnjs");
var ConnectionString = "SERVER=ict_tcp;DATABASE=biolive;HOST=128.1.9.144;SERVICE=1541;UID=biouser;PWD=bihif20;";
ibmdb.open(ConnectionString, function (err, connection) {
if (err)
{
console.log("an error occured:> "+err);
return;
}
connection.query("select 1 from mytab1", function (err1, rows)
{
if (err1) console.log(err1);
else console.log(rows);
connection.close(function(err2)
{
if(err2) console.log(err2);
});
});
});
The problem was that my CSDK files were not complete I did not have the gls(global locale support) folder, which provides language support for informix .Incase you know you have set the environment variables properly but still get errors, try checking your CSDK files if all are installed properly or some are missing.

redis Error : ERR wrong number of arguments for 'set' command

i have an error with redis set command on local redis server(127.0.0.1:6379)
versions:
npm version : 2.15.0;
node version : 4.4.2;
nodejs verison : 0.10.25;
redis version : 2.7.1;
Error:
events.js:141 throw er; // Unhandled 'error' event
ReplyError: ERR wrong number of arguments for 'set' command at parseError
(/opt/xxx/xxx/node_modules/redis/node_modules/redis
parser/lib/parser.js:193:12) at parseType
(/opt/xxx/xxx/node_modules/redis/node_modules/redis-
parser/lib/parser.js:303:14)
all of my codes look like this:
redis.set("key","value")
on my local machine the code is running successfully , but on aws linux machine i got this error.
var matchedMaps = map.get(publicURIField);
if(matchedMaps) {
matchedMaps.forEach(function(matchedMap){
var patternToValidate = matchedMap.pattern;
var type = matchedMap.type;
var tagID = matchedMap.tagID;
var patternToCheck = "cs-uri-stem";
var patternToSave = "";
if(type==1){
patternToCheck = "c-referrer";
}
var regexToFind = new RegExp(patternToValidate.substring(1,patternToValidate.length-1));
var matchedPattern;
if (regexToFind.test(rawLogParsed[patternToCheck].toString())) {
if (matchedMap.regexType=="&"){
matchedMap.patterns.forEach(function(patternObject){
var key = patternObject.pattern.split("=")[0];
var value = rawLogParsed[patternToCheck].toString().split(key)[1];
if(rawLogParsed[patternToCheck].toString().split(key)[1].split("&")){
value = rawLogParsed[patternToCheck].toString().split(key)[1].split("&")[0];
}
patternToSave += key+value+"&";
});
}else{
matchedMap.patterns.forEach(function(patternObject){
if(patternObject.pattern.indexOf("*")>-1){
patternObject.pattern = patternObject.pattern.replace(/\*!/g, '.*');
}
patternToSave += rawLogParsed[patternToCheck].toString().match(patternObject.pattern)+"/";
});
}
patternToSave = patternToSave.substring(0,patternToSave.length-1);
var matchedField = publicURIField,matchedPattern = patternToSave
,key = tagID + "_"+userID+"_"+ matchedField + "_" + matchedPattern + "_" + type + "_" + fixedMinuteNumber;
if (tagUsageInfo[startKeyForRedis+key] == undefined) {
var tagObject = {
pattern:matchedPattern,
matchedField:matchedField,
userID:userID,
tagName:matchedMap.tagName,
monthNumber:parseInt(mMonthToCheck),
minuteNumber: parseInt(fixedMinuteNumber),
hourNumber: parseInt(yearMonthDayHourToCheck),
dayNumber: parseInt(yearMonthDayToCheck),
tagID: tagID,
matchedPattern: matchedPattern,
totalRequests: 1,
totalEgress: parseInt(bytes),
totalTransfered: parseInt(bytes),
totalRest: parseInt(totalWorld),
totalUS: parseInt(totalUS)
}
if(isIngress){
tagObject.totalIngres += parseInt(bytes);
}
dbclient1.set(startKeyForRedis+"tagUsage_"+key,JSON.stringify(tagObject));
tagUsageInfo[startKeyForRedis+"tagUsage_"+key] = startKeyForRedis+key;
}
else {
dbclient1.get(startKeyForRedis+"tagUsage_"+key, function(err, tagObject) {
var tagObjectJson = JSON.parse(tagObject);
tagObjectJson.totalRequests += 1;
tagObjectJson.totalEgress += parseInt(bytes);
tagObjectJson.totalTransfered += parseInt(bytes);
tagObjectJson.totalRest += parseInt(totalWorld);
tagObjectJson.totalUS += parseInt(totalUS);
tagObjectJson.totalRequests += 1;
if(isIngress){
tagObject.totalIngres += parseInt(bytes);
}
dbclient1.del(startKeyForRedis+"tagUsage_"+key);
dbclient1.set(startKeyForRedis+"tagUsage_"+key, JSON.stringify(tagObjectJson));
});
}
}
});
}
any help?
1)If your trying to run redis on windows set accepts only two arguments cause the redis version issue
2)try latest version of redis on linux it will work
Try installing this version of Redis on windows from the following link. You can find more information here https://github.com/ServiceStack/redis-windows
This link provides three options to install Redis on windows
Option 1) Install Redis on Ubuntu on Windows
Option 2) Running the latest version of Redis with Vagrant
Option 3) Running Microsoft's native port of Redis
I personally prefer option 3.
Hope this helped. Thanks.
all of my codes look like this: [...]
It's not important how all of your code looks like. It's important how the specific line that caused the problem looks like but unfortunately you didn't include it.
The errors that you provided include some files and line numbers but you seem to have removed the ones that are related to your code. If you read those messages carefully then you should be able to know what lines those errors are related to and focus on those lines.
If the errors show up on a server and not on your desktop then I would suspect that maybe you're trying to use some environment variables or files on the file system to populate some variables in your program, and those are not available on the server resulting in putting undefined there.
You will surely find the problem when you add console.log() statements to every place where you want to access Redis so that you first print it and then call to Redis. That way at least you will know what data is causing the problem. I suspect that you are having some undefined values or something like that.
Remember that JSON.stringify(undefined) returns undefined instead of a valid JSON string. Something like that may be causing problems. Adding debug messages will help to narrow it down.
Some extra advice: You can use prefix parameter of the redis module then you will not have to add startKeyForRedis+ all over the place. You can set a prefix once and have it prepended automatically. See the docs:
https://www.npmjs.com/package/redis
I was doing learning to use KUE a nodejs library for job scheduling that uses redis for saving data.
I got this error while running client.js(that puts jobs in queue) and worker.js(that process the schedule jobs).
I was running worker before running the client and that is why this happened.
I reversed the order and everything went fine!
To fix this error on windows Redis from v.3 required.
That's why I've took zipped release 3.0.504 from here and now all is working.
Quite simple.
I have faced similar type of error which was because of older version of Redis. This is compatibility issue which fixes a bug in Redis after Redis 2.6.12. Make sure you install recent version of Redis v3.X.

How to Know if an specific windows service is installed with Node js?

I'm new in Node JS.
I'm building an new desktop app with web-kit.
One of my requirements is verify if an determinate service is installed on Windows. How can I do that on Node js?
I know how to find the application at the process list with Node Js. But what I really need is whether it is installed, because it can be stopped, but installed.
This will get you an array of all installed services:
var exec = require("child_process").exec;
exec("sc query state= all", function(err, stdout) {
var lines = stdout.toString().split("\r\n").filter(function (line) {
return line.indexOf("SERVICE_NAME") !== -1;
}).map(function (line) {
return line.replace("SERVICE_NAME: ", "");
});
console.log(lines);
});

Node.js to DB2 (using ibm_db)

I've followed the instructions: https://www.ibm.com/developerworks/community/blogs/pd/entry/using_ibm_db2_from_node_js4?maxresults=15&page=0&lang=en
for a 32-bit install of Ubuntu.
It seems to have installed correctly and I can run require('ibm_db'). Using the sample code provided (nodedb2test.js), no matter what database parameters I use I get the error:
node nodedb2test.js
Test program to access DB2 sample database
*** stack smashing detected ***: node terminated
Aborted (core dumped)
Heres the sample code:
/*require the ibm_db module*/
var ibmdb = require('ibm_db');
console.log("Test program to access DB2 sample database");
ibmdb.open("DRIVER={DB2};DATABASE=testdb;UID=username;PWD=password;HOSTNAME=localhost;port=3000", function(err, conn)
{
if(err) {
console.error("error: ", err.message);
}
});
Also I looks the version of DB2 I need to connect to is version 6. I have installed BM Data Server Driver version 10.5, does this correspond to the version of DB2? It appears below v9.1 drivers are not available.
At time of writing this works for me.
C:\Development\Javascript>node -p "process.arch"
x64
C:\Development\Javascript>node -p "process.platform"
win32
C:\Development\Javascript>node -p "process.version"
v14.17.5
C:\Development\Javascript>npm install ibm_db
var ibmdb = require("ibm_db");
const config = require("config");
const hostname = config.get("db2.hostname");
const username = config.get("db2.username");
const password = config.get("db2.password");
ibmdb.open("DRIVER={DB2};DATABASE=bludb;HOSTNAME=" + hostname + ";UID=" + username + ";PWD=" + password + ";PORT=31198;PROTOCOL=TCPIP;SECURITY=SSL", function (err, conn){
if (err) return console.log(err);
conn.query("SELECT * FROM orders", function (err, data) {
if (err) console.log(err);
console.log(data);
conn.close(function () {
console.log('done');
});
});
});
We can use ibm_db without installing IBM Data Server Driver Package too. ibm_db internally uses DB2 V10.5FP5 ODBC/CLI driver to talk to DB2 server. Please share the platform info and OS version where you have installed ibm_db. In june'14, ibm_db was supported on Linuxppc, AIX and zLinux platforms, but latest release is supporting. If latest driver is not working for you, please open an issue on github.com/ibmdb/node-ibm_db/issues/new . Thanks.

Resources