SQL data return array data types? MSSQL Node

I have successfully accessed a table from an MSSQL node, but the data my query returns is not coming importing into an array of proper datatype.

The VR1148 data fails because its not an integer? Well, how do I initialize the import variables to be of proper type?

The result of your query string is forcing the value to be interpreted as an integer by SQL. You must surround your string with single quotes for SQL to properly see it as a string.

include single quotes arouond the content of the msg.payload for SQL to know it's a string.
pld = pld + "WHERE '" + msg.payload + "' in (select value from string... blah blah blah"

resulting string will be like this .. WHERE 'VR1148' in(select value from string... blah blah blah

1 Like

Also, when using SQL Server (or any SQL), you should avoid building string queries as it opens you up to SQLi hacks

Here is how you would (should) do this using node-red-contrib-MSSQL-PLUS


1 Like

@Steve-Mcl ,

Great idea. Well, I seem to have broken it. I get the dreaded "TypeError: sql.ConnectionPool is not a constructor" error. You posted to someone with this problem, and this is what I did. I used the pallate to uninstall MSSQL and installed MSSQL-Plus. Unfortunately, I dont really know where node-red is installed, nor how to manipulate it via ssh. Its like its not really on my server. I suppose it could be a docker or something. What I do know, is I cannot reboot the server because the server is supporting other things. I have to ping my admin to restart it and thats a pain.

So, in that post, you describe how you uninstall and install nodes. However, not what to do after the fact.

Lastly, a bit off topic... I see a LOT of things about how node red is basically only to play around in a test environment. However, I was planning to use this for as an applet between a few PLCs and SQL in a production environment. My NodeRed is on a full featured HP server, not on a Rasberry Pi. Should I be concerned about using NodeRed in this manner? I would have no clue how else to tackle such a project.


Definitely not. It works and it works well. Why prototype on node-red, test it works then rewrite it in a complied application that will prevent all the nice runtime monitoring and ease of fix in the event of a bug. In my previous job I used node red to gather thousands of data points from lots of different PLCs, atlas copco tooling, hundreds of Fanuc robots & more, present the data in MQTT and store them in a database. It would have been crazy to replicate this in a custom application or a proprietary application.


Thats absurd.

We use Node RED in a corporate setting, for various tasks.

  • Automating our work force decisions.
  • Tracking 600+ vehicles (tracking private/personal mileage via GSM/GPS odometer units) - affecting monthly invoices for engineers
  • Integrating with our client systems
  • And running my entire home :nerd_face:

I do believe its used by Samsung also for their Smart Eco System, where users can sign up to an automation platform

1 Like

Also the Raspberry Pi is not a toy computer, it's a range of small, low power computers, some specifically designed for industrial uses.

Your application might push the I/O, memory, or CPU constraints (or not), in which case a beefier server might be appropriate. A few PLCs and SQL isn't going to need a supercomputer.

Of course you might get fired for recommending free software on a single board computer. :upside_down_face:

@marcus-j-davies , @jbudd , @Steve-Mcl ,

I might have been a bit unclear there. The notion was not my idea that node-red was suitable for production or not. I have seen a lot of forum posts that have said that it isnt. I havent personally seen anything specifically unreliable with it at all. I have installed it on a VM on a HP server, and its working great. I was wanting some real reason why it would NOT be proper for a production setup. I intend to use it as such, because I have no capacity to develop any other API.

1 Like

@Steve-Mcl ,

My fault for hijacking my own post, but what can you give me for advice on what do to now that I have this ConnectionPool error? Its too late to do what you do when installing/uninstalling. Its broke, and I need it fixed.

I guess the only thing I can come up with, is if you require parallel processing.
Node RED is based on Node JS, which is based on Javascript.

javascript is single threaded, so if your project requires multithreading, then you might need to get creative to get around these barriers.

that's all I have :sweat_smile:


Hmm, this is interesting. I was wondering how I would use this for multiple PLC's of identical setup, and identical function. I was thinking I would use multiple MQTT inputs, becuase there would be the case where more than one PLC would trigger node-red at the same time. I was thinking that each PLC would use a different port number to distinguish between them. I will cross that bridge later. But, I think I can figure that out. Ill post another thread on that one.

See here for the event loop model
I'll stop now - as I am way off topic :sweat_smile:

That is not the way to do it. You would have one MQTT broker and the PLCs would publish to different top level topics with the same structure underneath. You don't need to worry about multiple PLCs publishing at the same time, the network layer and the broker will sort that out.

Also, although node-red is single threaded, provided you have sufficient processor power that is usually irrelevant and the messaging architecture gives the impression of everything happening at once. The only time it is an issue is if you have a task that needs a large amount of processor in one go, image processing for example, in which case you might need to farm that out to a separate process.

MQTT would use a different TOPIC. The broker would be on the same port. Then you'd need a PLC that can speak MQTT... If you used TCP, then you'd need each PLC to be on a different port. MQTT would be the best way to ensure you catch all asynchronous values. Node-RED can also be used with TCP because each port connection would be monitored separately. I would suggest you "MODEL" or test your methods and then you can see if there would be any bandwidth failures.

The reason you see the many instances of "TESTING" is because the programming format makes it incredibly easy to test and figure things out to create efficient means of solving problems. That is the one thing that I like about Node-RED.

Question: Since the first question was about MSSQL, are you collecting data from PLC's to send to a SQL Server? Can you give a more direct description of your project? Thanks.

Hi Steve do you have an example of flow for extract data for fanuc robot?

Sorry, no. As stated it was in my previous job.

Not difficult though, it used a list (array) of objects --> split node that ran the following flow for each robot: HTTP Request node to grab specific pages from the robots web server, split out the IO, Registers and alarms, publish them to MQTT and/or store interesting items in database.

Hi Steve, thanks for your answer, excuse me do you have a manual or how can know the meaning of the variables from the fanuc robot?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.