bestlong / node-red-contrib-mssql-plus

A Node-RED node to read and write to Microsoft MS SQL Databases
MIT License
31 stars 18 forks source link

"TypeError: sql.ConnectionPool is not a constructor" #22

Closed davidsavoie1 closed 3 years ago

davidsavoie1 commented 4 years ago

Hi! When I try to configure a node to connect to the MSSQL database, I get this error on deploy:

"TypeError: sql.ConnectionPool is not a constructor"

Any hint as to what to look for? Thank you very much!

SoEpe commented 4 years ago

+1

same issue here ;)

bestlong commented 4 years ago

Quickly try connect to SQL 2K in docker is work. please provide more info.

$ docker run -it -p 1880:1880 --name mynodered nodered/node-red

> node-red-docker@1.0.3 start /usr/src/node-red
> node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data"

15 Jan 14:50:23 - [info]

Welcome to Node-RED
===================

15 Jan 14:50:23 - [info] Node-RED version: v1.0.3
15 Jan 14:50:23 - [info] Node.js  version: v10.18.0
15 Jan 14:50:23 - [info] Linux 4.9.184-linuxkit x64 LE
15 Jan 14:50:24 - [info] Loading palette nodes
15 Jan 14:50:24 - [info] Settings file  : /data/settings.js
15 Jan 14:50:24 - [info] Context store  : 'default' [module=memory]
15 Jan 14:50:24 - [info] User directory : /data
15 Jan 14:50:24 - [warn] Projects disabled : editorTheme.projects.enabled=false
15 Jan 14:50:24 - [info] Flows file     : /data/flows.json
15 Jan 14:50:24 - [info] Creating new flow file
15 Jan 14:50:24 - [warn]

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

15 Jan 14:50:24 - [info] Server now running at http://127.0.0.1:1880/
15 Jan 14:50:24 - [info] Starting flows
15 Jan 14:50:24 - [info] Started flows
15 Jan 14:50:54 - [info] Installing module: node-red-contrib-mssql-plus, version: 0.3.2
15 Jan 14:51:04 - [info] Installed module: node-red-contrib-mssql-plus
15 Jan 14:51:04 - [info] Added node types:
15 Jan 14:51:04 - [info]  - node-red-contrib-mssql-plus:MSSQL-CN
15 Jan 14:51:04 - [info]  - node-red-contrib-mssql-plus:MSSQL
15 Jan 14:52:31 - [info] Stopping flows
15 Jan 14:52:31 - [info] Stopped flows
15 Jan 14:52:31 - [info] Starting flows
15 Jan 14:52:31 - [info] Started flows
15 Jan 14:52:37 - [info] [MSSQL-CN:myMSSQL] Connected to server : dbs2.xxx.com.tw, database : PROD_DEV, port : 1433, user : sa
davidsavoie1 commented 4 years ago

I'm really sorry, but I don't use Docker and I don't quite understand what I should be doing to provide you with more information. A is not a constructor type of error really seems to be originating from the plugin code...

bestlong commented 4 years ago

@davidsavoie1 OS, node-red, other install nodes version ? if u can provide flow code, that will be great to debug.

davidsavoie1 commented 4 years ago

I'm developping with Node-RED v1.0.3 deployed on a RaspberryPI. I don't know all the configurations of the rPI, since I'm only in charge of the Node-RED workflow.

I'm sorry but I don't have the flow code anymore since I had to move to basic node-red-contrib-mssql in order to make everything work...

Steve-Mcl commented 4 years ago

@davidsavoie1 / @SoEpe it would be nice if you could please try again.

If there is a bug I will fix it.

The original MSSQL node had many issues and short comings (e.g. doesnt return multiple queries, if you have 2 connections it can get confused and execute against the wrong node, doesnt have option to throw errors, doesnt show you the final rendered query sent to DB (so you dont know whats happening to your mustache) + plus more.

please include node -v and node-red version in your reply.

also check to see if you have any other MSSQL node installed (other MSSQL node-red nodes installed at the same time WILL cause a conflict and possibly be related to this error)

Steve-Mcl commented 4 years ago

Following the recent fixes #29 and #28 It might be this issue was inadvertantly fixed (it is feasable) so I will close this issue for now.

If the problem returns - please re-open this issue.

Please include node -v and node-red version in your reply.

And also check to see if you have any other MSSQL contrib nodes installed (other MSSQL node-red contrib nodes installed at the same time can cause a conflict and possibly be related to this error)

SirMusic commented 3 years ago

I'm currently having the same issue with an Electron app I'm working on -- I'm very new to nodeJS dev, and dev in general, so this might be an ID10T error, but regardless, I can post whatever information you need if you can help resolve my issue.

Thank you

node -v v12.18.2

npm -v 6.14.7


const sql = require('mssql')

const config = { user: 'DevAdmin', password: '*', server: 'localhost', database: '***', port: '1433' }; function stolenFromSomeone() { var conn = new sql.ConnectionPool(config); conn.connect().then(function () { var request = new sql.Request(conn); request.query("select * from *****").then(function (recordSet) { console.log(recordSet); conn.close(); }).catch(function (err) { console.log(err); conn.close(); }); }).catch(function (err) { console.log(err); }); }

stolenFromSomeone();


"Uncaught TypeError: sql.ConnectionPool is not a constructor"

Steve-Mcl commented 3 years ago

@SirMusic what version of node-red are you using? Also, have you updated to the latest version of node-red-contrib-mssql-plus (v0.5.0) (you can check in the manage pallete of node-red)

Or is this something you are experiencing outside of node-red-contrib-mssql-plus and just after some help?

barneymc commented 3 years ago

Same error. My version of mssql looks good (6.2.3) so not sure why this error is happening. Any help greatly appreciated.

"TypeError: sql.ConnectionPool is not a constructor"

node-red-contrib-mssql-plus 0.6.1 node mssql 6.2.3 node-red 1.0.6 node 10.22

Steve-Mcl commented 3 years ago

Hi @barneymc , could you select the offending MSSQL node & export it (CTRL+E, copy)then paste it in a reply like this...

``` [paste flow json between backticks] ```

Question - did you switch from another version (e.g. mssql)? or update from an earlier version of mssql-plus? or is this the first time using a mssql node in this node-red instance?

barneymc commented 3 years ago

hey Steve - Pasted/Copied a flow from another server (Windows to Linux), noticed the mssql node-red was missing, installed it - so it never worked on this server to begin within. The original (production) windows node-red has different versions of everything compared to above, so troubleshooting is hard [apples/oranges]...

I'm seeing Connection refused from command line .....issue might be connectivity - let me investigate nc -zv SERVER_NAME 1433

barneymc commented 3 years ago

[{"id":"356df693.45df0a","type":"tab","label":"Activity","disabled":false,"info":""},{"id":"fc440902.b23aa8","type":"inject","z":"356df693.45df0a","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":200,"wires":[["9f941324.9bcba"]]},{"id":"9f941324.9bcba","type":"function","z":"356df693.45df0a","name":"","func":"msg.topic='select top 10 * from system_logging'\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":200,"wires":[["e0028990.7b1268"]]},{"id":"e0028990.7b1268","type":"MSSQL","z":"356df693.45df0a","mssqlCN":"1027cfce.66f65","name":"","outField":"payload","returnType":0,"throwErrors":1,"query":"","modeOpt":"","modeOptType":"execute","queryOpt":"","queryOptType":"editor","paramsOpt":"","paramsOptType":"none","params":[],"x":540,"y":200,"wires":[[]]},{"id":"1027cfce.66f65","type":"MSSQL-CN","z":"","tdsVersion":"7_4","name":"********","server":"********","port":"1433","encyption":true,"database":"*******","useUTC":false,"connectTimeout":"","requestTimeout":"","cancelTimeout":"","pool":"","parseJSON":false,"enableArithAbort":true}]
``
Steve-Mcl commented 3 years ago

Hi, hopefully this is an easy one...

the query editor is selected but the query is empty (you also have "stored procedure" selected instead of query)... image

however, you also seem to be trying to pass in a query in msg.topic... image

you have 2 choices...

  1. Enter the query in the node like this... image

OR

  1. Set the query to come from msg.topic... image

Please let me know if this fixes your issue.

(and obviously you need to fix the connection issue :) )

Steve-Mcl commented 3 years ago

Closing this issue until @barneymc comes back feedback.