# Node red can't connect sql server

**URL:** <https://discourse.nodered.org/t/node-red-cant-connect-sql-server/75327>\
**Category:** General\
**Created:** [17 February 2023 06:44 UTC](https://discourse.nodered.org/t/node-red-cant-connect-sql-server/75327 "2023-02-17T06:44:02Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![komkitPP](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/komkitpp/32/76273_2.png) [@komkitPP](https://discourse.nodered.org/u/komkitPP)\
**Post date:** [18 February 2023 23:54 UTC](https://discourse.nodered.org/t/node-red-cant-connect-sql-server/75327/21 "2023-02-18T23:54:04Z")

</div>

Thanks Steve! It works  
If it wasn't for you help , I wouldn't be able to do it. 💓 💓 💓

---

<div class="post-metadata">

**Author:** ![komkitPP](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/komkitpp/32/76273_2.png) [@komkitPP](https://discourse.nodered.org/u/komkitPP)\
**Post date:** [20 February 2023 13:48 UTC](https://discourse.nodered.org/t/node-red-cant-connect-sql-server/75327/22 "2023-02-20T13:48:49Z")

</div>

how to use data msg.payload = value to push into database

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/5/65d6437acb53813d5ec36d51606ed840d467e93f.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/3/f3bf30304242f165d775daaa975a66326c5cca79.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 February 2023 14:03 UTC](https://discourse.nodered.org/t/node-red-cant-connect-sql-server/75327/23 "2023-02-20T14:03:00Z")

</div>

Firstly, dont post picture of code (since i cannot copy & correct it for you)

`````  
`paste code between backticks like this`  
`````

Next, dont build queries in node - use the parameters of the MSSQL-PLUS node

---

<div class="post-metadata">

**Author:** ![komkitPP](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/komkitpp/32/76273_2.png) [@komkitPP](https://discourse.nodered.org/u/komkitPP)\
**Post date:** [20 February 2023 14:08 UTC](https://discourse.nodered.org/t/node-red-cant-connect-sql-server/75327/24 "2023-02-20T14:08:36Z")

</div>

```auto
example##
var value = 6
msg.payload = value
return msg

```

```auto
How to reteive data msg.payload = value to use

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 February 2023 14:51 UTC](https://discourse.nodered.org/t/node-red-cant-connect-sql-server/75327/25 "2023-02-20T14:51:34Z")

</div>

ummm that code is nothing like the 2 pictures above!  
Anyhow, what I was saying was Dont build SQL Querys in code (to avoid SQL injection hacks) - use the parameters on the MSSQL-PLUS node...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/d/6d1a48f0718b05bf04485adf683fbac4ffd373ed.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/55ac98475bf607fbae41b4a9715c54534f4aedfd.png)

---

<div class="post-metadata">

**Author:** ![komkitPP](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/komkitpp/32/76273_2.png) [@komkitPP](https://discourse.nodered.org/u/komkitPP)\
**Post date:** [20 February 2023 15:19 UTC](https://discourse.nodered.org/t/node-red-cant-connect-sql-server/75327/26 "2023-02-20T15:19:26Z")

</div>

How to use the value from the first function to the second function?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f835a3ce62f180f32a52e4edccfa4314a85875ee.png)

This is function 17

```auto
var steel = 6;

msg.payload = steel;

return msg;

```

i want to use value of steel in function 18

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 February 2023 15:23 UTC](https://discourse.nodered.org/t/node-red-cant-connect-sql-server/75327/27 "2023-02-20T15:23:32Z")

</div>

Since you put the value of `steel` inside of `msg.payload` it will be available in the next function in exactly the same place. E.g. put `node.warn(msg.payload)` inside of function 18 and you will see the number six In the debug output.

You could even put the value into a completely different property example setting `msg.abc =123` In function 17 will mean the value of 123 will be available inside of `msg.abc` inside function 18.

Attach debug nodes to your functions and you will see exactly what the message contains. Be sure to set the debug nodes to show the complete message if you are using properties other than payload.

---

<div class="post-metadata">

**Author:** ![komkitPP](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/komkitpp/32/76273_2.png) [@komkitPP](https://discourse.nodered.org/u/komkitPP)\
**Post date:** [20 February 2023 15:31 UTC](https://discourse.nodered.org/t/node-red-cant-connect-sql-server/75327/28 "2023-02-20T15:31:56Z")

</div>

Do you have an example?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 February 2023 15:40 UTC](https://discourse.nodered.org/t/node-red-cant-connect-sql-server/75327/29 "2023-02-20T15:40:32Z")

</div>

An example of what? You asked how you could access the value in function 18 and I told you - it will be in the exact same place that you put it.

I think you are missing some fundamental knowledge around node-red and messages etc

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Following that, you should probably do some experimenting like adding inject and debug nodes and seeing what you get in the debug panel. Also look at the flow library and search the forum. There are thousands of examples and demonstrations.

Once you have the basics you will see that the questions you are asking are extremely basic beginner knowledge and you should know how to answer them yourself once you have done the above.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 April 2023 15:41 UTC](https://discourse.nodered.org/t/node-red-cant-connect-sql-server/75327/30 "2023-04-21T15:41:10Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/node-red-cant-connect-sql-server/75327.md?page=1)
