Search code examples
sqlnode.jsoracleerror-handlingnode-oracledb

Hot to fix : not connected error when execution the sql statement, DPI-1010:not connected?


When I execute an SQL statement in nodeJs, it tells me there is an error like this!

What will be the possible solutions?

    connection.execute("create table testmm (city varchar(10));", function(err, res) {
      if(err) {
        console.error(err);
      }
      else {
        console.log("LLLLLL");
        console.log(res);
      }
    });][1]

Solution

  • You're trying to connect to the SYSTEM account - don't do that unless you're doing admin work. If you want to create your own tables, then create an application user/schema and then connect as that user.

    I see you're working with a local database. Are you able to connect to it from SQL*PLUS or SQL Developer as the SYS user? If so, you can use that to unlock the SYSTEM account. Once that's done you can connect as either SYS or SYSTEM to create the new user. Here's an example script to do that:

    create user my_app identified by oracle  
    default tablespace users
    temporary tablespace temp;
    
    grant connect to my_app;
    grant resource to my_app;
    
    grant create view to my_app;
    

    After running that, you can update your code to use the new user's credentials to connect an create your table.

    Finally, when you go to execute your SQL statement, remove the trailing semicolon or you'll get another error.