# Set environment variable node MSSQL username ,password

**URL:** <https://discourse.nodered.org/t/set-environment-variable-node-mssql-username-password/63486>\
**Category:** General\
**Tags:** database\
**Created:** [5 June 2022 15:08 UTC](https://discourse.nodered.org/t/set-environment-variable-node-mssql-username-password/63486 "2022-06-05T15:08:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![HoussemLajili](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/houssemlajili/32/62669_2.png) [@HoussemLajili](https://discourse.nodered.org/u/HoussemLajili)\
**Post date:** [5 June 2022 15:08 UTC](https://discourse.nodered.org/t/set-environment-variable-node-mssql-username-password/63486/1 "2022-06-05T15:08:30Z")

</div>

is impossible to set an environment variable username, password in node-red-contrib-mssql-plus ??

I tried {{username}} and {{{username}}} but it didn't work

---

<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:** [5 June 2022 15:12 UTC](https://discourse.nodered.org/t/set-environment-variable-node-mssql-username-password/63486/2 "2022-06-05T15:12:13Z")

</div>

Are you certain the node environment has picked up those variables. A quick test would be to run an exec node and call set or export depending on your operating system & see if the env var is present - or use an inject (set payload to env `username`) then to debug node.

Additionally, environment variables in node red are only applied on startup, so if you have just adjusted the MSSQL config node. Then it won't pick up the environment variable until it is restarted.

---

<div class="post-metadata">

**Author:** ![HoussemLajili](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/houssemlajili/32/62669_2.png) [@HoussemLajili](https://discourse.nodered.org/u/HoussemLajili)\
**Post date:** [5 June 2022 15:20 UTC](https://discourse.nodered.org/t/set-environment-variable-node-mssql-username-password/63486/3 "2022-06-05T15:20:06Z")

</div>

i have this message

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/0/f0561f727ec9cb255024a934d3725a0219b58aab.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:** [5 June 2022 15:21 UTC](https://discourse.nodered.org/t/set-environment-variable-node-mssql-username-password/63486/4 "2022-06-05T15:21:12Z")

</div>

- Did you restart node-red AFTER setting up the MSSQL node {{username}}?
- Have you checked that the env var `username` actually has a value inside node-red?
  - Just because a terminal has this set does NOT mean the node-red inherits it (due to things like running as a service or different user)

---

<div class="post-metadata">

**Author:** ![HoussemLajili](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/houssemlajili/32/62669_2.png) [@HoussemLajili](https://discourse.nodered.org/u/HoussemLajili)\
**Post date:** [5 June 2022 15:26 UTC](https://discourse.nodered.org/t/set-environment-variable-node-mssql-username-password/63486/5 "2022-06-05T15:26:29Z")

</div>

this is exemple i check that the env var `username` exist

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/2/b20eb750301e69a6ecd707222d7cca4162f25e10.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:** [5 June 2022 15:33 UTC](https://discourse.nodered.org/t/set-environment-variable-node-mssql-username-password/63486/6 "2022-06-05T15:33:22Z")

</div>

Works for me.

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

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/c/0c5d152239acf3c27da701496ab8974f0a4c1a39.png)

What OS are you on?

Do you see the ENV VAR if you run this...

```auto
[{"id":"67000189.da769","type":"inject","z":"7741f79c9d2c194c","name":"Linux","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1330,"y":440,"wires":[["7e0062b2.c73adc"]]},{"id":"7e0062b2.c73adc","type":"exec","z":"7741f79c9d2c194c","command":"DISPLAY=:0 printenv","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":1538,"y":440,"wires":[["bd65cfa7.0626a"],[],[]]},{"id":"bd65cfa7.0626a","type":"function","z":"7741f79c9d2c194c","name":"","func":"var lines = msg.payload.split(\"\\n\")\nvar envvars = {};\nfor(let i = 0; i < lines.length; i++) {\n let line = lines[i];\n let parts = line.split(\"=\");\n envvars[parts[0]]=(parts[1]||\"\").trim();\n}\nmsg.payload = envvars;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1740,"y":460,"wires":[["36b59d59.44c5a2"]]},{"id":"36b59d59.44c5a2","type":"debug","z":"7741f79c9d2c194c","name":"Env Vars","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1740,"y":520,"wires":[]},{"id":"4490197a71c2ebe2","type":"inject","z":"7741f79c9d2c194c","name":"Windows","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1340,"y":500,"wires":[["8c2f83bf0c544107"]]},{"id":"8c2f83bf0c544107","type":"exec","z":"7741f79c9d2c194c","command":"set","addpay":false,"append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":1490,"y":500,"wires":[["bd65cfa7.0626a"],[],[]]}]

```

---

<div class="post-metadata">

**Author:** ![HoussemLajili](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/houssemlajili/32/62669_2.png) [@HoussemLajili](https://discourse.nodered.org/u/HoussemLajili)\
**Post date:** [5 June 2022 15:56 UTC](https://discourse.nodered.org/t/set-environment-variable-node-mssql-username-password/63486/7 "2022-06-05T15:56:24Z")

</div>

thank you the problem is solved, I had a problem related to the Docker configuration

---

<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:** [5 June 2022 18:11 UTC](https://discourse.nodered.org/t/set-environment-variable-node-mssql-username-password/63486/8 "2022-06-05T18:11:38Z")

</div>

Always wise to mention if you are using docker (hint: it's usually somehow related to the problem 😂)

---

<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:** [19 June 2022 18:12 UTC](https://discourse.nodered.org/t/set-environment-variable-node-mssql-username-password/63486/9 "2022-06-19T18:12:09Z")

</div>

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