# Regarding oracle error

**URL:** <https://discourse.nodered.org/t/regarding-oracle-error/12772>\
**Category:** General\
**Created:** [1 July 2019 07:09 UTC](https://discourse.nodered.org/t/regarding-oracle-error/12772 "2019-07-01T07:09:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramya](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@Ramya](https://discourse.nodered.org/u/Ramya)\
**Post date:** [1 July 2019 07:09 UTC](https://discourse.nodered.org/t/regarding-oracle-error/12772/1 "2019-07-01T07:09:48Z")

</div>

Hi Everyone, I am new to Node-Red, and I am storing the oracle details(like config) inside function node  
"oracledbuser": "username",  
"oracledbpassword": "password",  
"oracledbconstring": "IP addr:portnumber",  
"oracledbschema": "schema name",  
"tablevariable": "tablename",  
I am setting this as global.set and in other flow if i try to retrieve the table as global.get,  
var data = global.get('configvar').oracledbschema + `.` + global.get('configvar').tablevariable;  
I am getting the below error  
"TypeError: Cannot read property 'oracledbuser' of undefined"  
Please help anyone

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [1 July 2019 07:18 UTC](https://discourse.nodered.org/t/regarding-oracle-error/12772/2 "2019-07-01T07:18:31Z")

</div>

The error is complaining about oracledbuser, but the code you've shared doesn't mention that property... So I assume you have not shared the full code. That makes it tricky because if you have a typo in the code you haven't shared, we won't be able to spot it.

The other thing to check is whether you are sure you have injected the values into global context before this flow runs.

---

<div class="post-metadata">

**Author:** ![Divya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/divya/32/6208_2.png) [@Divya](https://discourse.nodered.org/u/Divya)\
**Post date:** [1 July 2019 07:23 UTC](https://discourse.nodered.org/t/regarding-oracle-error/12772/3 "2019-07-01T07:23:11Z")

</div>

Even I am facing the same error. I have used the following code

var config = {

"oracledbuser": "system",  
"oracledbpassword": "password",  
"oracledbconstring": "hostname:portno",  
"oracledbschema": "schemaname"

// "contactTesting":false  
}

global.set('appconfig',config);

return msg;

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 July 2019 07:49 UTC](https://discourse.nodered.org/t/regarding-oracle-error/12772/4 "2019-07-01T07:49:46Z")

</div>

You have not showed us the code where the error is shown. Also you have not answered whether you have checked that the code that accesses the global data has been run when you the code trying to access it is run.  
In function nodes the `node.warn()` function can be used to help debug what is going on, the results are shown in the debug panel, so after you set the global data you could insert  
`node.warn("Data written " + global.get('appconfig').oracledbuser)`  
and after you fetch it you could insert a similar line to show the value fetched.

---

<div class="post-metadata">

**Author:** ![Divya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/divya/32/6208_2.png) [@Divya](https://discourse.nodered.org/u/Divya)\
**Post date:** [1 July 2019 07:55 UTC](https://discourse.nodered.org/t/regarding-oracle-error/12772/5 "2019-07-01T07:55:31Z")

</div>

Hi Colin, the node-red install in my machine doesn't contain the global context file. I am working on fixing that. Maybe that is the cause for my issue.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 July 2019 10:08 UTC](https://discourse.nodered.org/t/regarding-oracle-error/12772/6 "2019-07-01T10:08:03Z")

</div>

I don't understand what you mean by the global context file, but I don't think it is anything to do with your problem.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [1 July 2019 14:26 UTC](https://discourse.nodered.org/t/regarding-oracle-error/12772/7 "2019-07-01T14:26:11Z")

</div>

I can’t remember if context is by default stored in memory or the file system. You should check your settings.js file to see what it is.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [1 July 2019 14:36 UTC](https://discourse.nodered.org/t/regarding-oracle-error/12772/8 "2019-07-01T14:36:26Z")

</div>

@Divya @Ramya are you both working on the same problem here?

Neither of you have shown how you are trying to use these context values as I pointed out in my first reply. Without that we won't make any progress.

---

<div class="post-metadata">

**Author:** ![Divya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/divya/32/6208_2.png) [@Divya](https://discourse.nodered.org/u/Divya)\
**Post date:** [2 July 2019 11:12 UTC](https://discourse.nodered.org/t/regarding-oracle-error/12772/9 "2019-07-02T11:12:39Z")

</div>

`[{"id":"9a8d0eaa.13183","type":"tab","label":"Pass Config data","disabled":false,"info":""},{"id":"472333ed.878fdc","type":"debug","z":"9a8d0eaa.13183","name":"Output","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":930,"y":440,"wires":[]},{"id":"e2ab9f25.2c4468","type":"function","z":"9a8d0eaa.13183","name":"Set Global config data","func":"\nvar config = {\n \n \"oracledbuser\": \"username\",\n \"oracledbpassword\": \"password\",\n \"oracledbconstring\": \"hostname:portno\",\n \"oracledbschema\": \"schemaName\",\n \"tableA\": \"A\",\n \"contactTesting\":false\n}\n\n\nglobal.set('appconfig',config);\n\nreturn msg;","outputs":1,"noerr":0,"x":660,"y":440,"wires":[["472333ed.878fdc"]]},{"id":"a337f083.a6afb8","type":"inject","z":"9a8d0eaa.13183","name":"Inject Config","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":590,"y":280,"wires":[["e2ab9f25.2c4468"]]},{"id":"6cca3160.aec958","type":"link in","z":"9a8d0eaa.13183","name":"Set Config","links":["23b54cad.2929f4","34d6a4f9.54829c","4bf382f8.75e14c","4f14999c.9e7a78","6f812b92.0ed244","7079efa7.d28d","78dc19a0.e77068","94ff8bbf.5c4238","9cb671ce.d9d89","9d7f0d52.8079d","b94f2961.6e82d8","baf0ddb0.57424","bc93b0eb.1e278","beb197bb.171b18","d7bbb3.503e845","f7440dac.711ba","6baec3ac.2c6254"],"x":415,"y":440,"wires":[["e2ab9f25.2c4468"]]}]`

The above flow is the configuration flow that I am linking to all my other flows. Here, I wanted to insert some data to my database via the custom node. Where, all the flows works in others system but not working in mine. I am using Ubuntu 16.04 LTS.  
I am using a custom node which helps in connecting my node-red API with the Oracle DB. Do we have any other node in node-red which does this job?

If we do have a node-red node to connect to oracle-db, then I don't think there's a use of the custom node.

oracle-db.html

```auto
<script type="text/javascript">
    RED.nodes.registerType('oracle-db', {
        category: 'Custom nodes',
        color: '#97CC36',
        defaults: {
            name: {
                value: ""
            }
        },
        inputs: 1,
        outputs: 1,
        icon: "white-globe.png",
        label: function () {
            return this.name || "Oracle DB";
        }
    });
</script>

<script type="text/x-red" data-template-name="oracle-db">

  

    <div class="form-row">
        <label for="node-input-name"><i class="icon-tag"></i> Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
 
</script>

<script type="text/x-red" data-help-name="oracle-db">
    <p>Node to Query Data from Oracle Database</p>
</script>

```

oracle-db.js

```auto
 var oracledb = require('oracledb');

 module.exports = function (RED) {

         function OracleDB(config) {

             RED.nodes.createNode(this, config);
             var node = this;
             node.status({});

             node.on('input', function (msg) {
                     // console.log(config.user);
                     // console.log(config.password);
                     // console.log(config.connect);
                     // console.log(msg.payload.query);

                     const global = node.context().global;
                     const config = global.get('appconfig');

                     if (!msg.payload.query) {
                         node.error("Input Query Missing in Payload");
                         node.status({
                             fill: "red",
                             shape: "dot",
                             text: "Input Query Missing in Payload"
                         });
                         return false;
                     }
                      console.log(global.get('appconfig').oracledbuser);
                     if (!config.oracledbuser || !config.oracledbpassword || !config.oracledbconstring) {
                             node.error(" Node Input Missing");
                             node.status({
                                 fill: "red",
                                 shape: "dot",
                                 text: "Node Input Missing"
                             });
                             return false;
                         }

                         oracledb.getConnection({
                                 user: config.oracledbuser,
                                 password: config.oracledbpassword,
                                 connectString: config.oracledbconstring
                             },
                             function (err, connection) {
                                 if (err) {
                                     console.error(err);
                                     return;
                                 }
                                 node.status({
                                     fill: "green",
                                     shape: "dot",
                                     text: "connected"
                                 });

                                 var options = {
                                     autoCommit: true
                                 }

                                 connection.execute(
                                     msg.payload.query, [],
                                     // params,
                                     options,
                                     function (err, result) {
                                         if (err) {
                                             doRelease(connection);
                                             console.log(err);
                                             return;
                                         }
                                         var records = result.rows;
                                         msg.responsedata = records ? records : null;
                                         msg.result = result;
                                         node.send(msg);
                                         doRelease(connection);
                                     });
                             });
                     });

                 function doRelease(connection) {
                     connection.close(
                         function (err) {
                             if (err)
                                 console.error(err.message);
                         });
                 }
             }

             RED.nodes.registerType("oracle-db", OracleDB);
         }

```

These are the custom node files that I am using.

---

<div class="post-metadata">

**Author:** ![Divya](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/divya/32/6208_2.png) [@Divya](https://discourse.nodered.org/u/Divya)\
**Post date:** [4 July 2019 07:37 UTC](https://discourse.nodered.org/t/regarding-oracle-error/12772/10 "2019-07-04T07:37:51Z")

</div>

I reinstalled oracle and node-red. It works fine now. Thanks for the guidance.
