0

I would like to insert data into an Oracle database table by using insertIntoTable which is referenced in the code below; The function isn't working but without it, the query works as intended.

let connection;
var oracledb = require('oracledb');

(async function() {
try{

    connection = await oracledb.getConnection({
    user : 'demo7',
    password : 'dbpass',
    connectString : 'localhost/induspdb'
    });
    console.log("Successfully connected to Oracle!");

  //function which insert result into table
    async function insertIntoTable(dateToday, fileFound, fileNotFound )
    {
    const query='insert into backupinfo (infdate,found,notfound) values (:1,:2,:3)';
    var binds=[dateToday,fileFound,fileNotFound];
    await connection.execute(query , binds, {autoCommit:true}); 
    }

  // module.exports.insertIntoTable=insertIntoTable;
  insertIntoTable('2019-09-06','rtx','agh');

} catch(err) {
    console.log("Error: ", err);
  } finally {
    if (connection) {
      try {
        await connection.close();
      } catch(err) {
        console.log("Error when closing the database connection: ", err);
      }
    }
  }

})()

Whenever I call this function and pass given arguments, this function should insert values into the table, here is the error output:

Successfully connected to Oracle!

    (node:10088) UnhandledPromiseRejectionWarning: Error: DPI-1010: not connected
    (node:10088) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an as
    ync function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
    (node:10088) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are n
    ot handled will terminate the Node.js process with a non-zero exit code.
3

2 Answers 2

1

Check that all the params of the binds are valid according the table type in the db. In addition, add before insertIntoTable "await" so the error wont be UnhandledPromiseRejection, and will be clearer.

Sign up to request clarification or add additional context in comments.

3 Comments

but in another js file when I call this await serverConnection.insertIntoTable(todayDate, fileF, fileNF); it give same error can you please help me to fix this also.
@JAWADKHAN Create a new question and include the code that's not working. You might want to work through this series: jsao.io/2017/06/… See the links at the bottom which cover callbacks, the Async module, promises, and async/await.
JAWADKHAN, Did you figure it out? If not send the current code so i will help.
0

Don’t release connections until you are done with them Otherwise you will get DPI-1010 error. Check your async logic once again

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.